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
go101 opened this issue Mar 4, 2022 · 10 comments
Closed

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

go101 opened this issue Mar 4, 2022 · 10 comments
Labels
NeedsInvestigation
Milestone

Comments

@go101
Copy link

@go101 go101 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
Contributor

@ianlancetaylor ianlancetaylor commented Mar 4, 2022

CC @griesemer

@ianlancetaylor ianlancetaylor added the NeedsInvestigation label Mar 4, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Mar 4, 2022
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Mar 4, 2022

Thanks, we can address this for 1.19.

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

@go101 go101 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

@griesemer griesemer commented Mar 4, 2022

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

@go101
Copy link
Author

@go101 go101 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

@go101
Copy link
Author

@go101 go101 commented Mar 4, 2022

sorry, remove one , from the last comment.

@go101
Copy link
Author

@go101 go101 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
@go101
Copy link
Author

@go101 go101 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

@go101
Copy link
Author

@go101 go101 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

@griesemer griesemer commented Mar 18, 2022

Closing as duplicate of #49482.

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

No branches or pull requests

3 participants