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

go/types, types2: missing error for invalid cycle in function declaration #43215

Open
findleyr opened this issue Dec 16, 2020 · 2 comments
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@findleyr
Copy link
Contributor

The following invalid cycle is currently detected by the compiler with the error "typechecking loop involving f".

func f([unsafe.Sizeof(f)]int) {}

https://play.golang.org/p/cfAFJHgsAkX

However no error is detected by go/types, both at master and in the dev.typeparams branch (where there have been some changes to cycle detection in function declarations).

CC @griesemer

@griesemer griesemer self-assigned this Dec 16, 2020
@griesemer griesemer added this to the Go1.17 milestone Dec 16, 2020
@findleyr findleyr self-assigned this Jan 22, 2021
@griesemer griesemer added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker and removed release-blocker labels Apr 14, 2021
@griesemer
Copy link
Contributor

griesemer commented Apr 20, 2021

I don't believe this is a bug, and certainly not a release blocker. The spec says:

The functions Alignof and Sizeof take an expression x of any type and return the alignment or size, respectively, of a hypothetical variable v as if v was declared via var v = x.

The size of a variable of function type is independent of the function type and always the same, so arguably this is valid code.

The spec also doesn't explicitly disallow it.

[edited]

Interestingly, we do get a bug (initialization cycle) for this code:

package p
import "unsafe"
var f func([unsafe.Sizeof(f)]int)

which is not an initialization cycle (there is no initialization expression). Again, this shouldn't be a problem for the compiler/type-checker either. In any case, these are not release-blockers.

For reference, gccgo accepts both these cases (possibly accidentally) without error and the function argument is [8]int on a 64-bit platform.

@griesemer
Copy link
Contributor

Re-opening per edited comment above.

@griesemer griesemer reopened this Apr 20, 2021
@griesemer griesemer modified the milestones: Go1.17, Backlog Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants