}
func (pw *pkgWriter) typeAndValue(x syntax.Expr) syntax.TypeAndValue {
- tv := x.GetTypeInfo()
- if tv.Type == nil {
+ tv, ok := pw.maybeTypeAndValue(x)
+ if !ok {
pw.fatalf(x, "missing Types entry: %v", syntax.String(x))
}
return tv
}
+
func (pw *pkgWriter) maybeTypeAndValue(x syntax.Expr) (syntax.TypeAndValue, bool) {
tv := x.GetTypeInfo()
+
+ // If x is a generic function whose type arguments are inferred
+ // from assignment context, then we need to find its inferred type
+ // in Info.Instances instead.
+ if name, ok := x.(*syntax.Name); ok {
+ if inst, ok := pw.info.Instances[name]; ok {
+ tv.Type = inst.Type
+ }
+ }
+
return tv, tv.Type != nil
}
panic(2)
}
- // Disabled for now - requires some noder work
- // TODO fix this
- // if g3(g1, 3) != g1(3) {
- // panic(3)
- // }
-
- // if g4(g2, 4) != "" {
- // panic(4)
- // }
+ if g3(g1, 3) != g1(3) {
+ panic(3)
+ }
+
+ if g4(g2, 4) != "" {
+ panic(4)
+ }
}
func g1[P any](x P) P { return x }