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

inconsistent error for let bound variables conflicting with static parameters #33135

Closed
thautwarm opened this issue Sep 2, 2019 · 4 comments
Closed
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior compiler:lowering Syntax lowering (compiler front end, 2nd stage)

Comments

@thautwarm
Copy link
Member

thautwarm commented Sep 2, 2019

EDIT:

julia> function f(x::T) where {C1, C2, T}
           let C1 = 1,
               C2 = 2
               (C1, C2, T)
           end
       end
f (generic function with 1 method)

julia> f(1)
ERROR: UndefVarError: C1 not defined
@timholy
Copy link
Member

timholy commented Sep 2, 2019

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.

@thautwarm
Copy link
Member Author

@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 C1 = 1.

Is this explanation clear to you?

@timholy
Copy link
Member

timholy commented Sep 2, 2019

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.

@timholy timholy added compiler:lowering Syntax lowering (compiler front end, 2nd stage) bug Indicates an unexpected problem or unintended behavior labels Sep 2, 2019
@timholy
Copy link
Member

timholy commented Sep 2, 2019

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.

@JeffBezanson JeffBezanson self-assigned this Sep 3, 2019
@JeffBezanson JeffBezanson changed the title About multiple dispatch, and let binding using the symbol of static parameters. inconsistent error for let bound variables conflicting with static parameters Sep 3, 2019
JeffBezanson added a commit that referenced this issue Sep 3, 2019
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.
KristofferC pushed a commit that referenced this issue Sep 5, 2019
…ars (#33145)

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.

(cherry picked from commit 0fc3f03)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior compiler:lowering Syntax lowering (compiler front end, 2nd stage)
Projects
None yet
Development

No branches or pull requests

3 participants