You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
changed the title [-]No error for missing method call if other property is accessed in conditional body[/-][+]No error for missing method call [/+]on Dec 6, 2019
The way the check is done for usage seems brittle. The only check that is done is for symbol id equality:
constfunctionIsUsedInBody=forEachChild(ifStatement.thenStatement,functioncheck(childNode): boolean|undefined{if(isIdentifier(childNode)){constchildSymbol=getSymbolAtLocation(childNode);if(childSymbol&&childSymbol.id===testedFunctionSymbol.id){// HERE returntrue;}}returnforEachChild(childNode,check);});
This has the drawback of not actually working at all for symbols which have not had an id assigned (and we get undefined === undefined). This could be fixed by using getSymbolId which would assign the id, or by direct object equality (since as far as I understand it the same symbol object should be used and id equality when assigned at this location seems no better) but this fix would not fix the following surprising behavior:
interfaceStatsBase{isDirectory(): boolean;}functionA(stats2: StatsBase,stats: StatsBase){if(stats.isDirectory){// no error because we access isDirectory on stat2stats2.isDirectory();// comment this and we get an error above}}
Activity
[-]No error for missing method call if other property is accessed in conditional body[/-][+]No error for missing method call [/+]MartinJohns commentedon Dec 7, 2019
This will only report an error if
strictNullChecksis enabled, andstats.isDirectoryis a non-nullable function. See #33178 and #9041.mjbvz commentedon Dec 7, 2019
This is in strict mode:
RyanCavanaugh commentedon Dec 9, 2019
It looks like we're confused by any reference to
statsin the body if theifdragomirtitian commentedon Dec 26, 2019
The way the check is done for usage seems brittle. The only check that is done is for symbol
idequality:This has the drawback of not actually working at all for
symbolswhich have not had an id assigned (and we getundefined === undefined). This could be fixed by usinggetSymbolIdwhich would assign the id, or by direct object equality (since as far as I understand it the same symbol object should be used andidequality when assigned at this location seems no better) but this fix would not fix the following surprising behavior:Playground Link
The symbols
isDirectoryis used, in theifcondition and in the body but the target is different.Proposed solution:
getSymbolIdfor when comparing symbol idstestedNodeis a property access)