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: syntax error for valid type parameter list #51488

Closed
zigo101 opened this issue Mar 4, 2022 · 10 comments
Closed

cmd/compile: syntax error for valid type parameter list #51488

zigo101 opened this issue Mar 4, 2022 · 10 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@zigo101
Copy link

zigo101 commented Mar 4, 2022

What version of Go are you using (go version)?

$ go version
go version go1.18rc1 linux/amd64

What did you do?

type foo[T *string,] struct{x T}      // okay
type bar[T *string|bool,] struct{x T} // syntax error: unexpected comma; expecting ]
type tik[T *string|bool, X int] struct{x T} // syntax error: unexpected comma; expecting ]

What did you expect to see?

compiles okay

What did you see instead?

fails to compile

@ianlancetaylor
Copy link
Member

CC @griesemer

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 4, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Mar 4, 2022
@ianlancetaylor
Copy link
Member

Thanks, we can address this for 1.19.

@griesemer griesemer self-assigned this Mar 4, 2022
@zigo101
Copy link
Author

zigo101 commented Mar 4, 2022

more forms:

type bar[T *string|bool] struct{x T}
type bar[T *[]int|bool] struct{x T}

@griesemer
Copy link
Contributor

We're aware of them, thanks. See #49482.

@zigo101
Copy link
Author

zigo101 commented Mar 4, 2022

So this is covered in spec?

package main

const T, int, bool = 1, 1, 2

type bar[T *int|bool] struct{}

func main() {
	var _ bar
}

But it looks this one is not covered in spec.
*string is also a type literal, but this line fails to compile.
Maybe it should always compile? Because *string may not be a constant,

type bar[T **string] struct{} // *string (type) is not an expression

@zigo101
Copy link
Author

zigo101 commented Mar 4, 2022

sorry, remove one , from the last comment.

@zigo101
Copy link
Author

zigo101 commented Mar 5, 2022

Is it worth considering this case: #6386 (comment) ?

[edit]: maybe it is not worth it. If array could be declared as const, array index expressions should be banned in the length expressions of array declarations.

@griesemer griesemer changed the title cmd/compile: fails on the code looking legal cmd/compile: syntax error for valid type parameter list Mar 5, 2022
@zigo101
Copy link
Author

zigo101 commented Mar 5, 2022

Not sure whether or not this is intended:

type C4[T ([]int)] struct{}      // compiles okay
type C5[T ([]int)|bool] struct{} // fails to compile

@zigo101
Copy link
Author

zigo101 commented Mar 15, 2022

Luckily, aConstString[aConstInteger] is not a constant.

const S = "abcde"
const int = 2
const N = S[2]*int // error

type _ [S[2]*int] struct{} // error

@griesemer
Copy link
Contributor

Closing as duplicate of #49482.

@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

4 participants