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

Struct field cannot have same name as type variable unless the type of the field is also the type variable #46668

Closed
llbit opened this issue Sep 7, 2022 · 2 comments

Comments

@llbit
Copy link
Contributor

llbit commented Sep 7, 2022

I noticed that a struct like struct S{T} T::String end does not compile. Therefore I expected that struct S{T} T::T end would likewise not compile because both of them have a field with the same name as a type variable (the error message seems to imply there is a name collision causing the problem). However, the latter case was accepted by the Julia compiler.

This seems like a compiler error or an oversight in Julia semantics. Also the error message could be greatly improved to explain what the compiler thinks is wrong in the context of the surface syntax.

julia> VERSION
v"1.8.0"

julia> struct S{T} T::String end
ERROR: syntax: function argument and static parameter names must be distinct around REPL[2]:1
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

julia> struct S{T} T::T end

julia>
@vtjnash
Copy link
Member

vtjnash commented Sep 7, 2022

Incidentally fixed by #44664, since it removed the implied where clauses

@llbit
Copy link
Contributor Author

llbit commented Sep 8, 2022

I tested it again in v"1.9.0-DEV.1301" and the error is gone. Thank you!

@llbit llbit closed this as completed Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants