t.Errorf("got %s, want %s", got, want)
}
}
+
+func TestIssue69092(t *testing.T) {
+ const src = `
+package p
+
+var _ = T{{x}}
+`
+
+ file := mustParse(src)
+ conf := Config{Error: func(err error) {}} // ignore errors
+ info := Info{Types: make(map[syntax.Expr]TypeAndValue)}
+ conf.Check("p", []*syntax.File{file}, &info)
+
+ // look for {x} expression
+ outer := file.DeclList[0].(*syntax.VarDecl).Values.(*syntax.CompositeLit) // T{{x}}
+ inner := outer.ElemList[0] // {x}
+
+ // type of {x} must have been recorded
+ tv, ok := info.Types[inner]
+ if !ok {
+ t.Fatal("no type found for {x}")
+ }
+ if tv.Type != Typ[Invalid] {
+ t.Fatalf("unexpected type for {x}: %s", tv.Type)
+ }
+}
default:
// TODO(gri) provide better error messages depending on context
check.error(e, UntypedLit, "missing type in composite literal")
- x.mode = invalid
- return
+ // continue with invalid type so that elements are "used" (go.dev/issue/69092)
+ typ = Typ[Invalid]
+ base = typ
}
switch utyp := coreType(base).(type) {
t.Errorf("got %s, want %s", got, want)
}
}
+
+func TestIssue69092(t *testing.T) {
+ const src = `
+package p
+
+var _ = T{{x}}
+`
+
+ fset := token.NewFileSet()
+ file := mustParse(fset, src)
+ conf := Config{Error: func(err error) {}} // ignore errors
+ info := Info{Types: make(map[ast.Expr]TypeAndValue)}
+ conf.Check("p", fset, []*ast.File{file}, &info)
+
+ // look for {x} expression
+ outer := file.Decls[0].(*ast.GenDecl).Specs[0].(*ast.ValueSpec).Values[0].(*ast.CompositeLit) // T{{x}}
+ inner := outer.Elts[0] // {x}
+
+ // type of {x} must have been recorded
+ tv, ok := info.Types[inner]
+ if !ok {
+ t.Fatal("no type found for {x}")
+ }
+ if tv.Type != Typ[Invalid] {
+ t.Fatalf("unexpected type for {x}: %s", tv.Type)
+ }
+}
default:
// TODO(gri) provide better error messages depending on context
check.error(e, UntypedLit, "missing type in composite literal")
- x.mode = invalid
- return
+ // continue with invalid type so that elements are "used" (go.dev/issue/69092)
+ typ = Typ[Invalid]
+ base = typ
}
switch utyp := coreType(base).(type) {