Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: "any" should be an alias for "interface{}", not a defined type #49665

Closed
cherrymui opened this issue Nov 18, 2021 · 9 comments
Closed
Labels
NeedsFix release-blocker
Milestone

Comments

@cherrymui
Copy link
Member

@cherrymui cherrymui commented Nov 18, 2021

The spec says

the predeclared type any is an alias for the empty interface.

I would interpret it as "any" being an alias type, not a defined type, i.e. essentially type any = interface{}.

But it seems the compiler treats "any" as a defined type, for example,

package main

import "fmt"

var x any
var y interface{}

func main() {
	fmt.Printf("%T\n%T\n", &x, &y)
}

This prints

*any
*interface {}

(In contrast, the spec says "byte" is an alias for "uint8", and both byte and uint8 print as "uint8".)

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Nov 18, 2021

CC @griesemer

@ianlancetaylor ianlancetaylor added Documentation NeedsInvestigation labels Nov 18, 2021
@ianlancetaylor ianlancetaylor added this to the Go1.18 milestone Nov 18, 2021
@findleyr
Copy link
Contributor

@findleyr findleyr commented Nov 18, 2021

See also #49583. I expected that change to only affect error messages from the type checker, not %T formatting (if indeed this is a consequence of that change).

@findleyr
Copy link
Contributor

@findleyr findleyr commented Nov 18, 2021

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Nov 18, 2021

Yeah, that code is incorrect if any should be an alias.

We should be creating types.AnyType as an anonymous type and then directly declaring it as the name any. That's a little more involved than just changing TFORW to TINTER but not that invasive.

A bit more involved will be finding all the byte / rune logic that specially handles those aliases for error messages and replicate it to handle any too.

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Nov 18, 2021

If we confirm that any should be an alias, not a defined type, I can fix cmd/compile.

@randall77
Copy link
Contributor

@randall77 randall77 commented Nov 18, 2021

@thanm This may be related to the any problem you were trying to fix in DWARF.

@griesemer
Copy link
Contributor

@griesemer griesemer commented Nov 18, 2021

any is definitively and alias for interface{}.

@griesemer
Copy link
Contributor

@griesemer griesemer commented Nov 18, 2021

See also the forthcoming spec (search for predeclared type any).

@mdempsky mdempsky self-assigned this Nov 18, 2021
@mdempsky mdempsky added NeedsFix and removed Documentation NeedsInvestigation labels Nov 18, 2021
@mdempsky mdempsky changed the title spec, cmd/compile: clarify if "any" is a defined type cmd/compile: "any" should be an alias for "interface{}", not a defined type Nov 18, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Nov 18, 2021

Change https://golang.org/cl/365354 mentions this issue: cmd/compile: handle anyas alias likebyteandrune``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix release-blocker
Projects
None yet
Development

No branches or pull requests

7 participants