Skip to content

Commit 0c89194

Browse files
FlandiaYingmanLPTK
authored andcommitted
Validate number of arguments in application
1 parent 0cdc10d commit 0c89194

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

hkmc2/shared/src/main/scala/hkmc2/semantics/ImplicitResolver.scala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,13 @@ class ImplicitResolver(tl: TraceLogger)
144144
val paramss = tdf.params
145145
(paramss zip argss).foreach:
146146
case (ps, Term.Tup(args)) =>
147-
// * TODO: Check the arity.
148-
// if ps.paramCountUB
149-
// then if ps.paramCountLB != args.length then
150-
// raise(ErrorReport(msg"Expected ${ps.paramCountLB.toString()} arguments, " +
151-
// msg"got ${args.length.toString()}" -> base.toLoc :: Nil))
152-
// else if ps.paramCountLB > args.length then
153-
// raise(ErrorReport(msg"Expected at least ${ps.paramCountLB.toString()} arguments, " +
154-
// msg"got ${args.length.toString()}" -> base.toLoc :: Nil))
155-
assert(ps.params.sizeCompare(args) === 0)
147+
if ps.paramCountUB
148+
then if ps.paramCountLB != args.length then
149+
raise(ErrorReport(msg"Expected ${ps.paramCountLB.toString()} arguments, " +
150+
msg"got ${args.length.toString()}" -> base.toLoc :: Nil))
151+
else if ps.paramCountLB > args.length then
152+
raise(ErrorReport(msg"Expected at least ${ps.paramCountLB.toString()} arguments, " +
153+
msg"got ${args.length.toString()}" -> base.toLoc :: Nil))
156154
(ps.params zip args).foreach((p, arg) => resolveArg(p, arg)(base))
157155
case _ =>
158156
lastWords("Other argument forms.")

hkmc2/shared/src/test/mlscript/backlog/ToTriage.mls

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ set g.0 = g.0 + 1
8989
:todo // TODO instrument Predef
9090
:re
9191
id(1, 2)
92+
//│ ╔══[ERROR] Expected 1 arguments, got 2
93+
//│ ║ l.91: id(1, 2)
94+
//│ ╙── ^^
9295
//│ = 1
9396

9497
// ——— ——— ———
@@ -149,7 +152,7 @@ f of
149152
2
150153
of 3
151154
//│ ╔══[PARSE ERROR] Expected end of input; found indented block instead
152-
//│ ║ l.150: of 3
155+
//│ ║ l.153: of 3
153156
//│ ╙── ^^
154157
//│ = [function]
155158

@@ -180,7 +183,7 @@ object Oops with
180183
:e
181184
Oops.fakeField
182185
//│ ╔══[ERROR] Object 'Oops' does not contain member 'fakeField'
183-
//│ ║ l.181: Oops.fakeField
186+
//│ ║ l.184: Oops.fakeField
184187
//│ ╙── ^^^^^^^^^^
185188
//│ = 1
186189

@@ -246,7 +249,7 @@ object Cls(x) with
246249
:e
247250
Cls.x
248251
//│ ╔══[ERROR] Object 'Cls' does not contain member 'x'
249-
//│ ║ l.247: Cls.x
252+
//│ ║ l.250: Cls.x
250253
//│ ╙── ^^
251254
//│ ═══[RUNTIME ERROR] Error: Access to required field 'x' yielded 'undefined'
252255

@@ -274,23 +277,23 @@ module Example with
274277
// whoops
275278
val a = this
276279
//│ ╔══[PARSE ERROR] Expected block after type declaration body; found newline instead
277-
//│ ║ l.273: module Example with
280+
//│ ║ l.276: module Example with
278281
//│ ║ ^
279-
//│ ║ l.274: // whoops
282+
//│ ║ l.277: // whoops
280283
//│ ╙──
281284
//│ ╔══[PARSE ERROR] Expected an expression; found block instead
282-
//│ ║ l.275: val a = this
285+
//│ ║ l.278: val a = this
283286
//│ ╙── ^
284287
//│ ╔══[PARSE ERROR] Expected end of input; found indented block instead
285-
//│ ║ l.275: val a = this
288+
//│ ║ l.278: val a = this
286289
//│ ╙── ^^
287290

288291
// ——— ——— ———
289292

290293
:fixme // ("Not in scope" error)
291294
let xs = new Oopsie
292295
//│ ╔══[ERROR] Name not found: Oopsie
293-
//│ ║ l.291: let xs = new Oopsie
296+
//│ ║ l.294: let xs = new Oopsie
294297
//│ ╙── ^^^^^^
295298
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: xs (class hkmc2.semantics.VarSymbol)
296299

hkmc2/shared/src/test/mlscript/basics/StrTest.mls

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,43 @@ concat of
1717

1818
// TODO (~) should be sanitized
1919

20+
:e
2021
(~)("a", "b", "c")
22+
//│ ╔══[ERROR] Expected 2 arguments, got 3
23+
//│ ║ l.21: (~)("a", "b", "c")
24+
//│ ╙── ^
2125
//│ = "ab"
2226

2327

28+
:e
2429
(~)("a")
30+
//│ ╔══[ERROR] Expected 2 arguments, got 1
31+
//│ ║ l.29: (~)("a")
32+
//│ ╙── ^
2533
//│ = "aundefined"
2634

2735
:ge
2836
~"a"
2937
//│ ╔══[COMPILATION ERROR] Unexpected type annotations ~"a"
30-
//│ ║ l.28: ~"a"
38+
//│ ║ l.36: ~"a"
3139
//│ ╙── ^^^
3240

3341

3442
:ge
3543
~("a", "b")
3644
//│ ╔══[COMPILATION ERROR] Unexpected type annotations ~{ "a"; "b" }
37-
//│ ║ l.35: ~("a", "b")
45+
//│ ║ l.43: ~("a", "b")
3846
//│ ╙── ^^^
3947

4048

4149
:pe
4250
:ge
4351
~ of "a", "b"
4452
//│ ╔══[PARSE ERROR] Expected start of statement in this position; found 'of' keyword instead
45-
//│ ║ l.43: ~ of "a", "b"
53+
//│ ║ l.51: ~ of "a", "b"
4654
//│ ╙── ^^
4755
//│ ╔══[PARSE ERROR] Expected end of input; found literal instead
48-
//│ ║ l.43: ~ of "a", "b"
56+
//│ ║ l.51: ~ of "a", "b"
4957
//│ ╙── ^^^
5058
//│ ═══[COMPILATION ERROR] Unexpected type annotations ~<error>
5159

0 commit comments

Comments
 (0)