fix(lsp): walk assignment target bases for name diagnostics
`_x.a = 1`, `_x.a += 2`, `_x[0] = 3` and `_x.a: T = v` only visited the assigned value, so an unresolved target base never produced the unknown-name warning.
This commit is contained in:
1 parent
2c65cea97f
commit
dbee021cd1
1 file changed
+23
-1
@@ -1582,6 +1582,12 @@ def _WalkChecks(pool: memhub.MemManager*, doc: LspDocuments.LspDocument*,
|
||||
or dst.kind == LspTypes.LT_AGG or dst.kind == LspTypes.LT_UNKNOWN):
|
||||
_EmitTypeError(pool, doc, an.value,
|
||||
"a pointer/`own` value cannot be stored into a value-typed variable; declare the target as `own T` / `T*`, or dereference explicitly (`*p`)", errors)
|
||||
if an.target is not None and an.target.kind() == ast.ASTKind.Attribute:
|
||||
_WalkChecksExprs(pool, doc, a, ws, table_pool, ast.Attribute*(an.target).value, errors)
|
||||
elif an.target is not None and an.target.kind() == ast.ASTKind.Subscript:
|
||||
sb_an: ast.Subscript* = ast.Subscript*(an.target)
|
||||
_WalkChecksExprs(pool, doc, a, ws, table_pool, sb_an.value, errors)
|
||||
_WalkChecksExprs(pool, doc, a, ws, table_pool, sb_an.slice, errors)
|
||||
if an.target is not None and an.target.kind() == ast.ASTKind.Name:
|
||||
tn: ast.Name* = ast.Name*(an.target)
|
||||
if tn.id is not None:
|
||||
@@ -1599,7 +1605,17 @@ def _WalkChecks(pool: memhub.MemManager*, doc: LspDocuments.LspDocument*,
|
||||
while ti < int(len(asn.targets)):
|
||||
tgt: ast.AST* = asn.targets.get(sizet(ti))
|
||||
ti += 1
|
||||
if tgt is None or tgt.kind() != ast.ASTKind.Name:
|
||||
if tgt is None:
|
||||
continue
|
||||
if tgt.kind() == ast.ASTKind.Attribute:
|
||||
_WalkChecksExprs(pool, doc, a, ws, table_pool, ast.Attribute*(tgt).value, errors)
|
||||
continue
|
||||
if tgt.kind() == ast.ASTKind.Subscript:
|
||||
sb_t: ast.Subscript* = ast.Subscript*(tgt)
|
||||
_WalkChecksExprs(pool, doc, a, ws, table_pool, sb_t.value, errors)
|
||||
_WalkChecksExprs(pool, doc, a, ws, table_pool, sb_t.slice, errors)
|
||||
continue
|
||||
if tgt.kind() != ast.ASTKind.Name:
|
||||
continue
|
||||
tt: LspIndex.LspTarget* = _TargetAtNode(ws, pool, table_pool, a, doc, tgt)
|
||||
if tt is None or tt.detail is None:
|
||||
@@ -1639,6 +1655,12 @@ def _WalkChecks(pool: memhub.MemManager*, doc: LspDocuments.LspDocument*,
|
||||
continue
|
||||
if k == ast.ASTKind.AugAssign:
|
||||
ag: ast.AugAssign* = ast.AugAssign*(s)
|
||||
if ag.target is not None and ag.target.kind() == ast.ASTKind.Attribute:
|
||||
_WalkChecksExprs(pool, doc, a, ws, table_pool, ast.Attribute*(ag.target).value, errors)
|
||||
elif ag.target is not None and ag.target.kind() == ast.ASTKind.Subscript:
|
||||
sb_ag: ast.Subscript* = ast.Subscript*(ag.target)
|
||||
_WalkChecksExprs(pool, doc, a, ws, table_pool, sb_ag.value, errors)
|
||||
_WalkChecksExprs(pool, doc, a, ws, table_pool, sb_ag.slice, errors)
|
||||
if ag.target is not None and ag.value is not None:
|
||||
tt_a: LspIndex.LspTarget* = _TargetAtNode(ws, pool, table_pool, a, doc, ag.target)
|
||||
if tt_a is not None and tt_a.detail is not None:
|
||||
|
||||
Reference in new issue
Block a user