Skip to content

Commit 4c495e6

Browse files
abap34aviatesk
andauthored
Fix handling lower bound in type parameter (#37)
Co-authored-by: Shuhei Kadowaki <[email protected]>
1 parent 4b4fb1e commit 4c495e6

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

src/desugaring.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3266,7 +3266,7 @@ function analyze_typevar(ctx, ex)
32663266
(ex[1], nothing, ex[2])
32673267
elseif k == K">:" && numchildren(ex) == 2
32683268
kind(ex[2]) == K"Identifier" || throw(LoweringError(ex[2], "expected type name"))
3269-
(ex[2], ex[1], nothing)
3269+
(ex[1], ex[2], nothing)
32703270
else
32713271
throw(LoweringError(ex, "expected type name or type bounds"))
32723272
end

test/functions.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ end
202202
end
203203
""") === ((1, (), false), (1, (2,), true), (1, (2, 3), true))
204204

205+
@test JuliaLowering.include_string(test_mod, """
206+
begin
207+
f_def_typevar_with_lowerbound(x::T) where {T>:Int} =
208+
(x, @isdefined(T))
209+
(f_def_typevar_with_lowerbound(1), f_def_typevar_with_lowerbound(1.0))
210+
end
211+
""") == ((1, true), (1.0, false))
212+
205213
@test JuliaLowering.include_string(test_mod, """
206214
begin
207215
function f_def_slurp(x=1, ys...)

test/functions_ir.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,34 @@ end
199199
18 TestMod.f
200200
19 (return %₁₈)
201201

202+
########################################
203+
# Static parameter with lower bound
204+
function f(::S{T}) where T >: X
205+
T
206+
end
207+
#---------------------
208+
1 (method TestMod.f)
209+
2 latestworld
210+
3 TestMod.X
211+
4 (= slot₁/T (call core.TypeVar :T %₃ core.Any))
212+
5 TestMod.f
213+
6 (call core.Typeof %₅)
214+
7 TestMod.S
215+
8 slot₁/T
216+
9 (call core.apply_type %%₈)
217+
10 (call core.svec %%₉)
218+
11 slot₁/T
219+
12 (call core.svec %₁₁)
220+
13 SourceLocation::1:10
221+
14 (call core.svec %₁₀ %₁₂ %₁₃)
222+
15 --- method core.nothing %₁₄
223+
slots: [slot₁/#self#(!read) slot₂/_(!read)]
224+
1 static_parameter₁
225+
2 (return %₁)
226+
16 latestworld
227+
17 TestMod.f
228+
18 (return %₁₇)
229+
202230
########################################
203231
# Static parameter which is used only in the bounds of another static parameter
204232
# See https://github.com/JuliaLang/julia/issues/49275

test/typedefs_ir.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ A where X <: UB
2525
# where expression with lower bound
2626
A where X >: LB
2727
#---------------------
28-
1 TestMod.X
29-
2 (call core.TypeVar :LB %₁ core.Any)
30-
3 (= slot₁/LB %₂)
31-
4 slot₁/LB
28+
1 TestMod.LB
29+
2 (call core.TypeVar :X %₁ core.Any)
30+
3 (= slot₁/X %₂)
31+
4 slot₁/X
3232
5 TestMod.A
3333
6 (call core.UnionAll %%₅)
3434
7 (return %₆)

0 commit comments

Comments
 (0)