Skip to content

Commit 4228f0a

Browse files
committed
Test all lowering error messages!
1 parent 0494237 commit 4228f0a

19 files changed

+374
-162
lines changed

src/desugaring.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ function expand_property_destruct(ctx, ex)
318318
lhs = ex[1]
319319
@assert kind(lhs) == K"tuple"
320320
if numchildren(lhs) != 1
321-
throw(LoweringError(ex, "Property destructuring must use a single `;` before the property names, eg `(; a, b) = rhs`"))
321+
throw(LoweringError(lhs, "Property destructuring must use a single `;` before the property names, eg `(; a, b) = rhs`"))
322322
end
323323
params = lhs[1]
324324
@assert kind(params) == K"parameters"

test/assignments.jl

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -71,37 +71,5 @@ let
7171
end
7272
""") === 10
7373

74-
#-------------------------------------------------------------------------------
75-
# Invalid assignment left hand sides with specific error messages
76-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
77-
a.(b) = c
78-
""")
79-
80-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
81-
T[x y] = z
82-
""")
83-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
84-
T[x; y] = z
85-
""")
86-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
87-
T[x ;;; y] = z
88-
""")
89-
90-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
91-
[x, y] = z
92-
""")
93-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
94-
[x y] = z
95-
""")
96-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
97-
[x; y] = z
98-
""")
99-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
100-
[x ;;; y] = z
101-
""")
102-
103-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
104-
1 = x
105-
""")
10674

10775
end

test/assignments_ir.jl

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,75 @@ end
222222
3 (call top.setindex! %%₁)
223223
4 (return %₁)
224224

225+
########################################
226+
# Error: Invalid lhs in `=`
227+
a.(b) = rhs
228+
#---------------------
229+
LoweringError:
230+
a.(b) = rhs
231+
└───┘ ── invalid dot call syntax on left hand side of assignment
232+
233+
########################################
234+
# Error: Invalid lhs in `=`
235+
T[x y] = rhs
236+
#---------------------
237+
LoweringError:
238+
T[x y] = rhs
239+
└────┘ ── invalid spacing in left side of indexed assignment
240+
241+
########################################
242+
# Error: Invalid lhs in `=`
243+
T[x; y] = rhs
244+
#---------------------
245+
LoweringError:
246+
T[x; y] = rhs
247+
└─────┘ ── unexpected `;` in left side of indexed assignment
248+
249+
########################################
250+
# Error: Invalid lhs in `=`
251+
T[x ;;; y] = rhs
252+
#---------------------
253+
LoweringError:
254+
T[x ;;; y] = rhs
255+
└────────┘ ── unexpected `;` in left side of indexed assignment
256+
257+
########################################
258+
# Error: Invalid lhs in `=`
259+
[x, y] = rhs
260+
#---------------------
261+
LoweringError:
262+
[x, y] = rhs
263+
└────┘ ── use `(a, b) = ...` to assign multiple values
264+
265+
########################################
266+
# Error: Invalid lhs in `=`
267+
[x y] = rhs
268+
#---------------------
269+
LoweringError:
270+
[x y] = rhs
271+
└───┘ ── use `(a, b) = ...` to assign multiple values
272+
273+
########################################
274+
# Error: Invalid lhs in `=`
275+
[x; y] = rhs
276+
#---------------------
277+
LoweringError:
278+
[x; y] = rhs
279+
└────┘ ── use `(a, b) = ...` to assign multiple values
280+
281+
########################################
282+
# Error: Invalid lhs in `=`
283+
[x ;;; y] = rhs
284+
#---------------------
285+
LoweringError:
286+
[x ;;; y] = rhs
287+
└───────┘ ── use `(a, b) = ...` to assign multiple values
288+
289+
########################################
290+
# Error: Invalid lhs in `=`
291+
1 = rhs
292+
#---------------------
293+
LoweringError:
294+
1 = rhs
295+
╙ ── invalid assignment location
296+

test/branching.jl

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -305,36 +305,21 @@ end
305305
end
306306

307307
@testset "symbolic goto/label" begin
308-
JuliaLowering.include_string(test_mod, """
309-
let
310-
a = []
311-
i = 1
312-
@label foo
313-
push!(a, i)
314-
i = i + 1
315-
if i <= 2
316-
@goto foo
317-
end
318-
a
319-
end
320-
""") == [1,2]
321308

322-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
323-
begin
309+
JuliaLowering.include_string(test_mod, """
310+
let
311+
a = []
312+
i = 1
313+
@label foo
314+
push!(a, i)
315+
i = i + 1
316+
if i <= 2
324317
@goto foo
325318
end
326-
""")
327-
328-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
329-
begin
330-
@label foo
331-
@label foo
332-
end
333-
""")
319+
a
320+
end
321+
""") == [1,2]
334322

335-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
336-
x = @label foo
337-
""")
338323
end
339324

340325
end

test/branching_ir.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,37 @@ end
202202
23 (pop_exception %₁)
203203
24 (return core.nothing)
204204

205+
########################################
206+
# Error: no symbolic label
207+
begin
208+
@goto foo
209+
end
210+
#---------------------
211+
LoweringError:
212+
begin
213+
@goto foo
214+
# └─┘ ── label `foo` referenced but not defined
215+
end
216+
217+
########################################
218+
# Error: duplicate symbolic label
219+
begin
220+
@label foo
221+
@label foo
222+
end
223+
#---------------------
224+
LoweringError:
225+
begin
226+
@label foo
227+
@label foo
228+
# └─┘ ── Label `foo` defined multiple times
229+
end
230+
231+
########################################
232+
# Error: using value of symbolic label
233+
x = @label foo
234+
#---------------------
235+
LoweringError:
236+
x = @label foo
237+
# └─┘ ── misplaced label in value position
238+

test/decls.jl

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,4 @@ end
4949
@test Core.get_binding_type(test_mod, :a_typed_global_2) === Int
5050
@test test_mod.a_typed_global_2 === 10
5151

52-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
53-
begin
54-
local x::T = 1
55-
local x::S = 1
56-
end
57-
""")
58-
59-
# Const not supported on locals
60-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
61-
const local x = 1
62-
""")
63-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
64-
let
65-
const x = 1
66-
end
67-
""")
68-
69-
# global type decls only allowed at top level
70-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
71-
function f()
72-
global x::Int = 1
73-
end
74-
""")
75-
7652
end

test/decls_ir.jl

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,48 @@ global xx::T = 10
8080
14 (return 10)
8181

8282
########################################
83-
# Type assert (TODO: move this?)
84-
x::T
83+
# Error: x declared twice
84+
begin
85+
local x::T = 1
86+
local x::S = 1
87+
end
8588
#---------------------
86-
1 TestMod.x
87-
2 TestMod.T
88-
3 (call core.typeassert %%₂)
89-
4 (return %₃)
89+
LoweringError:
90+
begin
91+
local x::T = 1
92+
local x::S = 1
93+
# └──┘ ── multiple type declarations found for `x`
94+
end
95+
96+
########################################
97+
# Error: Const not supported on locals
98+
const local x = 1
99+
#---------------------
100+
LoweringError:
101+
const local x = 1
102+
# ╙ ── unsupported `const` declaration on local variable
103+
104+
########################################
105+
# Error: Const not supported on locals
106+
let
107+
const x = 1
108+
end
109+
#---------------------
110+
LoweringError:
111+
let
112+
const x = 1
113+
# ╙ ── unsupported `const` declaration on local variable
114+
end
115+
116+
########################################
117+
# Error: global type decls only allowed at top level
118+
function f()
119+
global x::Int = 1
120+
end
121+
#---------------------
122+
LoweringError:
123+
function f()
124+
global x::Int = 1
125+
# └────┘ ── type declarations for global variables must be at top level, not inside a function
126+
end
90127

test/destructuring.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ let
8989
end
9090
""") == (1, [2,3], 4)
9191

92-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
93-
(xs..., ys...) = x
94-
""")
95-
9692
end
9793

9894

@@ -138,9 +134,6 @@ let
138134
end
139135
""") == (1, 2)
140136

141-
@test_throws LoweringError JuliaLowering.include_string(test_mod, "(x ; a, b) = rhs")
142-
@test_throws LoweringError JuliaLowering.include_string(test_mod, "(; a=1, b) = rhs")
143-
144137
end
145138

146139
end

test/destructuring_ir.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ end
8181
12 TestMod.as
8282
13 (return %₁₂)
8383

84+
########################################
85+
# Error: Slurping multiple args
86+
(xs..., ys...) = x
87+
#---------------------
88+
LoweringError:
89+
(xs..., ys...) = x
90+
# └────┘ ── multiple `...` in destructuring assignment are ambiguous
91+
8492
########################################
8593
# Recursive destructuring
8694
let
@@ -255,3 +263,19 @@ end
255263
16 TestMod.rhs
256264
17 (return %₁₆)
257265

266+
########################################
267+
# Error: Property destructuring with frankentuple
268+
(x ; a, b) = rhs
269+
#---------------------
270+
LoweringError:
271+
(x ; a, b) = rhs
272+
└────────┘ ── Property destructuring must use a single `;` before the property names, eg `(; a, b) = rhs`
273+
274+
########################################
275+
# Error: Property destructuring with values for properties
276+
(; a=1, b) = rhs
277+
#---------------------
278+
LoweringError:
279+
(; a=1, b) = rhs
280+
# └─┘ ── invalid assignment location
281+

test/functions.jl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,6 @@ begin
4545
end
4646
""") === (42, 255)
4747

48-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
49-
function ccall()
50-
end
51-
""")
52-
53-
@test_throws LoweringError JuliaLowering.include_string(test_mod, """
54-
function A.ccall()
55-
end
56-
""")
57-
5848
Base.include_string(test_mod,
5949
"""
6050
struct X end

0 commit comments

Comments
 (0)