@@ -4300,8 +4300,10 @@ def direct_lookup(self, key: "LookupKey") -> "Symbol":
4300
4300
4301
4301
def find_name (self , nestedName : ASTNestedName , templateDecls : List [Any ],
4302
4302
typ : str , templateShorthand : bool , matchSelf : bool ,
4303
- recurseInAnon : bool , searchInSiblings : bool ) -> List ["Symbol" ]:
4303
+ recurseInAnon : bool , searchInSiblings : bool ) -> Tuple [ List ["Symbol" ], str ]:
4304
4304
# templateShorthand: missing template parameter lists for templates is ok
4305
+ # If the first component is None,
4306
+ # then the second component _may_ be a string explaining why.
4305
4307
if Symbol .debug_lookup :
4306
4308
Symbol .debug_indent += 1
4307
4309
Symbol .debug_print ("find_name:" )
@@ -4316,6 +4318,9 @@ def find_name(self, nestedName: ASTNestedName, templateDecls: List[Any],
4316
4318
Symbol .debug_print ("recurseInAnon: " , recurseInAnon )
4317
4319
Symbol .debug_print ("searchInSiblings: " , searchInSiblings )
4318
4320
4321
+ class QualifiedSymbolIsTemplateParam (Exception ):
4322
+ pass
4323
+
4319
4324
def onMissingQualifiedSymbol (parentSymbol : "Symbol" ,
4320
4325
identOrOp : Union [ASTIdentifier , ASTOperator ],
4321
4326
templateParams : Any ,
@@ -4324,28 +4329,39 @@ def onMissingQualifiedSymbol(parentSymbol: "Symbol",
4324
4329
# Though, the correctPrimaryTemplateArgs does
4325
4330
# that for primary templates.
4326
4331
# Is there another case where it would be good?
4332
+ if parentSymbol .declaration is not None :
4333
+ if parentSymbol .declaration .objectType == 'templateParam' :
4334
+ raise QualifiedSymbolIsTemplateParam ()
4327
4335
return None
4328
4336
4329
- lookupResult = self ._symbol_lookup (nestedName , templateDecls ,
4330
- onMissingQualifiedSymbol ,
4331
- strictTemplateParamArgLists = False ,
4332
- ancestorLookupType = typ ,
4333
- templateShorthand = templateShorthand ,
4334
- matchSelf = matchSelf ,
4335
- recurseInAnon = recurseInAnon ,
4336
- correctPrimaryTemplateArgs = False ,
4337
- searchInSiblings = searchInSiblings )
4337
+ try :
4338
+ lookupResult = self ._symbol_lookup (nestedName , templateDecls ,
4339
+ onMissingQualifiedSymbol ,
4340
+ strictTemplateParamArgLists = False ,
4341
+ ancestorLookupType = typ ,
4342
+ templateShorthand = templateShorthand ,
4343
+ matchSelf = matchSelf ,
4344
+ recurseInAnon = recurseInAnon ,
4345
+ correctPrimaryTemplateArgs = False ,
4346
+ searchInSiblings = searchInSiblings )
4347
+ except QualifiedSymbolIsTemplateParam :
4348
+ return None , "templateParamInQualified"
4349
+
4338
4350
if lookupResult is None :
4339
4351
# if it was a part of the qualification that could not be found
4340
4352
if Symbol .debug_lookup :
4341
4353
Symbol .debug_indent -= 2
4342
- return None
4354
+ return None , None
4343
4355
4344
4356
res = list (lookupResult .symbols )
4345
4357
if len (res ) != 0 :
4346
4358
if Symbol .debug_lookup :
4347
4359
Symbol .debug_indent -= 2
4348
- return res
4360
+ return res , None
4361
+
4362
+ if lookupResult .parentSymbol .declaration is not None :
4363
+ if lookupResult .parentSymbol .declaration .objectType == 'templateParam' :
4364
+ return None , "templateParamInQualified"
4349
4365
4350
4366
# try without template params and args
4351
4367
symbol = lookupResult .parentSymbol ._find_first_named_symbol (
@@ -4355,9 +4371,9 @@ def onMissingQualifiedSymbol(parentSymbol: "Symbol",
4355
4371
if Symbol .debug_lookup :
4356
4372
Symbol .debug_indent -= 2
4357
4373
if symbol is not None :
4358
- return [symbol ]
4374
+ return [symbol ], None
4359
4375
else :
4360
- return None
4376
+ return None , None
4361
4377
4362
4378
def find_declaration (self , declaration : ASTDeclaration , typ : str , templateShorthand : bool ,
4363
4379
matchSelf : bool , recurseInAnon : bool ) -> "Symbol" :
@@ -6778,12 +6794,13 @@ def warn(self, msg):
6778
6794
templateDecls = ns .templatePrefix .templates
6779
6795
else :
6780
6796
templateDecls = []
6781
- symbols = parentSymbol .find_name (nestedName = name ,
6782
- templateDecls = templateDecls ,
6783
- typ = 'any' ,
6784
- templateShorthand = True ,
6785
- matchSelf = True , recurseInAnon = True ,
6786
- searchInSiblings = False )
6797
+ symbols , failReason = parentSymbol .find_name (
6798
+ nestedName = name ,
6799
+ templateDecls = templateDecls ,
6800
+ typ = 'any' ,
6801
+ templateShorthand = True ,
6802
+ matchSelf = True , recurseInAnon = True ,
6803
+ searchInSiblings = False )
6787
6804
if symbols is None :
6788
6805
symbols = []
6789
6806
else :
@@ -7089,12 +7106,21 @@ def findWarning(e): # as arg to stop flake8 from complaining
7089
7106
templateDecls = []
7090
7107
# let's be conservative with the sibling lookup for now
7091
7108
searchInSiblings = (not name .rooted ) and len (name .names ) == 1
7092
- symbols = parentSymbol .find_name (name , templateDecls , typ ,
7093
- templateShorthand = True ,
7094
- matchSelf = True , recurseInAnon = True ,
7095
- searchInSiblings = searchInSiblings )
7096
- # just refer to the arbitrarily first symbol
7097
- s = None if symbols is None else symbols [0 ]
7109
+ symbols , failReason = parentSymbol .find_name (
7110
+ name , templateDecls , typ ,
7111
+ templateShorthand = True ,
7112
+ matchSelf = True , recurseInAnon = True ,
7113
+ searchInSiblings = searchInSiblings )
7114
+ if symbols is None :
7115
+ if typ == 'identifier' :
7116
+ if failReason == 'templateParamInQualified' :
7117
+ # this is an xref we created as part of a signature,
7118
+ # so don't warn for names nested in template parameters
7119
+ raise NoUri (str (name ), typ )
7120
+ s = None
7121
+ else :
7122
+ # just refer to the arbitrarily first symbol
7123
+ s = symbols [0 ]
7098
7124
else :
7099
7125
decl = ast # type: ASTDeclaration
7100
7126
name = decl .name
0 commit comments