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
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@cherrymui
Copy link
Member

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

CC @griesemer

@ianlancetaylor ianlancetaylor added Documentation NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Nov 18, 2021
@ianlancetaylor ianlancetaylor added this to the Go1.18 milestone Nov 18, 2021
@findleyr
Copy link
Contributor

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

@mdempsky
Copy link
Member

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

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

@randall77
Copy link
Contributor

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

@griesemer
Copy link
Contributor

any is definitively and alias for interface{}.

@griesemer
Copy link
Contributor

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

@mdempsky mdempsky self-assigned this Nov 18, 2021
@mdempsky mdempsky added NeedsFix The path to resolution is known, but the work has not been done. and removed Documentation NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. 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

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

@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

7 participants