-
-
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
inconsistent error for let
bound variables conflicting with static parameters
#33135
Comments
Am I understanding correctly that you're asking for a new feature in which static parameters can be supplied with default values? What is the use case for this? In general the static parameters should be determined by the input types. |
@timholy No, it's okay to leave the non-dispatched static parameters undefined, i.e, I think this is expected: julia> function f(x::T) where {C1, C2, T}
C1
end
f (generic function with 1 method)
julia> f(1)
ERROR: UndefVarError: C1 not defined However, in my first post I used a let binding to enter a new scope, and bind Is this explanation clear to you? |
Nope. If this is a feature request, you need to clarify why you want this. If you think it's a bug (it's not), please ask questions on discourse. |
Oh wait, now I understand (sorry!): this is a bug report. Compare the following: julia> function g(x::T) where {C1, C2, T}
let C1 = 1, C2 = 2
return (C1, C2, T)
end
end
g (generic function with 1 method)
julia> function h(x::T) where {C, T}
let C = 1
return (C, T)
end
end
h (generic function with 1 method)
julia> h(nothing)
(1, Nothing)
julia> g(nothing)
ERROR: UndefVarError: C1 not defined
Stacktrace:
[1] g(::Nothing) at ./REPL[1]:3
[2] top-level scope at REPL[4]:1
julia> @code_lowered h(nothing)
CodeInfo(
1 ─ C = 1
│ %2 = Core.tuple(C, $(Expr(:static_parameter, 2)))
└── return %2
)
julia> @code_lowered g(nothing)
CodeInfo(
1 ─ C1 = 1
│ C2 = 2
│ %3 = Core.tuple($(Expr(:static_parameter, 1)), C2, $(Expr(:static_parameter, 3)))
└── return %3
) It's of course not how you should write Julia code, but the inconsistency is a bug. |
let
bound variables conflicting with static parameters
The static parameters of an outer scope should not be passed along to inner scopes; it instead needs to be handled by the lookup process iterating back to enclosing scopes.
EDIT:
The text was updated successfully, but these errors were encountered: