-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Foo{<:Any} accepts non-type parameters #52201
Comments
Duplicate of #9580? |
If we actually want(?) this behavior, it should be documented. |
Should we reopen #9580? |
Why was the other issue closed? @vtjnash ? Did we fix it somehow on nightly? |
Isn't it documented at https://docs.julialang.org/en/v1/manual/types/
? There are a few other references to the fact isbits values can be used as parameters throughout the page. Or am I missing what you're referring to? |
I think the documentation refers to julia> struct Foo2{x<:Real} end
julia> Foo2{2}()
ERROR: TypeError: in Foo2, in x, expected x<:Real, got a value of type Int64 so the fact that this works for |
I believe the issue is that non-types will match For values, I think we should use type assertion syntax. struct Foo{::Any}
end or struct Foo2{::Real}
end Of course we can already enforce this via an inner constructor using a type assertion. struct Foo3{T}
Foo3{T}() where T= new{T::Real}()
end
|
That would mislead users to think the constraint applies to the type itself, when it only applies to some of the type's instances. |
I'm not sure I see your point. |
The inner constructor can only enforce anything upon the instances of a type, not on the type itself. Furthermore, there are ways, such as |
I don't know whether to laugh or cry that this fundamental issue of Julia's type system in the case of type parameters has been rediscovered by yet another user. The initial issue #9580 is already more than 9 years old... I would love to help in any way I can to move things forward, but we need the core dev(s) to provide a unified and appropriate solution first. Otherwise, we are stuck with what we face. Please at least reopen the issue so that people are properly exposed to it. Regardless of if it's considered a bug of the language, keeping the issue closed is a negative attitude. |
This behavior, pointed out on discourse, seems like a bug (violating the documented meaning of
<:
):The text was updated successfully, but these errors were encountered: