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

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

findleyr opened this issue Dec 16, 2020 · 2 comments
Assignees
Milestone

Comments

@findleyr
Copy link
Contributor

@findleyr findleyr commented Dec 16, 2020

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
Copy link
Contributor

@griesemer 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 griesemer closed this Apr 20, 2021
@griesemer
Copy link
Contributor

@griesemer griesemer commented Apr 20, 2021

Re-opening per edited comment above.

@griesemer griesemer reopened this Apr 20, 2021
@griesemer griesemer removed this from the Go1.17 milestone Apr 20, 2021
@griesemer griesemer added this to the Backlog milestone Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants