]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/go/types/decl.go
[dev.typeparams] merge dev.regabi (618e3c1) into dev.typeparams
[gostls13.git] / src / go / types / decl.go
index bd2c5466617a78f747f24ce6e84a76b0b45d4270..f2e68bbd5c3fe38e08f978b4e7f74b9bd50e6573 100644 (file)
@@ -511,6 +511,20 @@ func (check *Checker) constDecl(obj *Const, typ, init ast.Expr, inherited bool)
 func (check *Checker) varDecl(obj *Var, lhs []*Var, typ, init ast.Expr) {
        assert(obj.typ == nil)
 
+       // If we have undefined variable types due to errors,
+       // mark variables as used to avoid follow-on errors.
+       // Matches compiler behavior.
+       defer func() {
+               if obj.typ == Typ[Invalid] {
+                       obj.used = true
+               }
+               for _, lhs := range lhs {
+                       if lhs.typ == Typ[Invalid] {
+                               lhs.used = true
+                       }
+               }
+       }()
+
        // determine type, if any
        if typ != nil {
                obj.typ = check.varType(typ)