-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
typealias in local scope doesn't always throw an error #18217
Comments
|
Also, this is kind of a dup of #12010 since that's what we lower this to. We do need a different error message though. |
What is wrong with local scope typealias ? If one cannot define parameterized types related to local scopes it will be difficult to manage if there are too many parameterized types. |
Local scope in functions is fine. Local scopes in a type declaration is currently a strange thing in Julia; it's not well defined what this is or what it should be. Within a type declaration you can (obviously) declare fields and constructors, but currently (strangely) a few other things as well -- but not type aliases. In other words, if you move the typealias into the type constructor, things should work fine. |
putting the typealias on ctor will make it available only in the function scope but it is actually required in class scope to declare member variables. |
It's kind of unclear what you're trying to accomplish and why you want typealias in local scope. |
With the current "strange" local scope in type definitions, the only thing we actually support is local functions. If you just want a shorter name for a useful type (like how julia> type A{T}
my_type(V) = Tuple{T,V}
A{V}(v::my_type(V)) = new(v[1], V)
x::T
t::DataType
end
julia> A{Int}((1, 1.2))
A{Int64}(1,Float64) |
I was trying to do something like we do for
|
In Julia, member functions (and member types) are defined outside the type's scope. immutable X{T} end
iterator_type{T}(::Type{X{T}}) = iterator(T)
value_type{T}(::Type{X{T}}) = value_type(T) Of course that's just a literal translation; the functions Note that these functions will be inlined and type-inferred in Julia, so that there is no overhead in doing so. |
close as dup of #12010 now that typealias is gone? |
We only evaluate type definition blocks once at the top level, and generally don't have "parameterized blocks" of code, e.g. that would run for each value of
as a shortcut for
One reason is that the syntax |
The text was updated successfully, but these errors were encountered: