Skip to content

cmd/compile: do not assume typos are new(expr) uses #75986

@rsc

Description

@rsc
% cat /tmp/x.go
package p

type MyType int

func f() {
	_ = new(myType)
	_ = new(myOtherType)
}
% go tool compile -lang=go1.25 /tmp/x.go
/tmp/x.go:6:6: new(expr) requires go1.26 or later (-lang was set to go1.25; check go.mod)
/tmp/x.go:6:10: undefined: myType
/tmp/x.go:7:6: new(expr) requires go1.26 or later (-lang was set to go1.25; check go.mod)
/tmp/x.go:7:10: undefined: myOtherType
% 

The "new(expr)" errors are misleading and inaccurate and should not be emitted unless the argument typechecked successfully and is actually an expression. It looks like the current rule is "is not a valid type", which is too broad.

If you do new(strings.BUILDER) then you get

/tmp/x.go:8:6: new(expr) requires go1.26 or later (-lang was set to go1.25; check go.mod)
/tmp/x.go:8:18: undefined: strings.BUILDER (but have Builder)

which is also bad.

Metadata

Metadata

Assignees

Labels

NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.release-blocker

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions