Skip to content

Commit

Permalink
Validate number of arguments in application
Browse files Browse the repository at this point in the history
  • Loading branch information
FlandiaYingman committed Feb 7, 2025
1 parent 7aad77e commit 242198a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,13 @@ class ImplicitResolver(tl: TraceLogger)
val paramss = tdf.params
(paramss zip argss).foreach:
case (ps, Term.Tup(args)) =>
// * TODO: Check the arity.
// if ps.paramCountUB
// then if ps.paramCountLB != args.length then
// raise(ErrorReport(msg"Expected ${ps.paramCountLB.toString()} arguments, " +
// msg"got ${args.length.toString()}" -> base.toLoc :: Nil))
// else if ps.paramCountLB > args.length then
// raise(ErrorReport(msg"Expected at least ${ps.paramCountLB.toString()} arguments, " +
// msg"got ${args.length.toString()}" -> base.toLoc :: Nil))
assert(ps.params.sizeCompare(args) === 0)
if ps.paramCountUB
then if ps.paramCountLB != args.length then
raise(ErrorReport(msg"Expected ${ps.paramCountLB.toString()} arguments, " +
msg"got ${args.length.toString()}" -> base.toLoc :: Nil))
else if ps.paramCountLB > args.length then
raise(ErrorReport(msg"Expected at least ${ps.paramCountLB.toString()} arguments, " +
msg"got ${args.length.toString()}" -> base.toLoc :: Nil))
(ps.params zip args).foreach((p, arg) => resolveArg(p, arg)(base))
case _ =>
lastWords("Other argument forms.")
Expand Down
19 changes: 11 additions & 8 deletions hkmc2/shared/src/test/mlscript/backlog/ToTriage.mls
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ set g.0 = g.0 + 1
:todo // TODO instrument Predef
:re
id(1, 2)
//│ ╔══[ERROR] Expected 1 arguments, got 2
//│ ║ l.91: id(1, 2)
//│ ╙── ^^
//│ = 1

// ——— ——— ———
Expand Down Expand Up @@ -149,7 +152,7 @@ f of
2
of 3
//│ ╔══[PARSE ERROR] Expected end of input; found indented block instead
//│ ║ l.150: of 3
//│ ║ l.153: of 3
//│ ╙── ^^
//│ = [function]

Expand Down Expand Up @@ -180,7 +183,7 @@ object Oops with
:e
Oops.fakeField
//│ ╔══[ERROR] Object 'Oops' does not contain member 'fakeField'
//│ ║ l.181: Oops.fakeField
//│ ║ l.184: Oops.fakeField
//│ ╙── ^^^^^^^^^^
//│ = 1

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

Expand Down Expand Up @@ -274,23 +277,23 @@ module Example with
// whoops
val a = this
//│ ╔══[PARSE ERROR] Expected block after type declaration body; found newline instead
//│ ║ l.273: module Example with
//│ ║ l.276: module Example with
//│ ║ ^
//│ ║ l.274: // whoops
//│ ║ l.277: // whoops
//│ ╙──
//│ ╔══[PARSE ERROR] Expected an expression; found block instead
//│ ║ l.275: val a = this
//│ ║ l.278: val a = this
//│ ╙── ^
//│ ╔══[PARSE ERROR] Expected end of input; found indented block instead
//│ ║ l.275: val a = this
//│ ║ l.278: val a = this
//│ ╙── ^^

// ——— ——— ———

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

Expand Down
16 changes: 12 additions & 4 deletions hkmc2/shared/src/test/mlscript/basics/StrTest.mls
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,43 @@ concat of

// TODO (~) should be sanitized

:e
(~)("a", "b", "c")
//│ ╔══[ERROR] Expected 2 arguments, got 3
//│ ║ l.21: (~)("a", "b", "c")
//│ ╙── ^
//│ = "ab"


:e
(~)("a")
//│ ╔══[ERROR] Expected 2 arguments, got 1
//│ ║ l.29: (~)("a")
//│ ╙── ^
//│ = "aundefined"

:ge
~"a"
//│ ╔══[COMPILATION ERROR] Unexpected type annotations ~"a"
//│ ║ l.28: ~"a"
//│ ║ l.36: ~"a"
//│ ╙── ^^^


:ge
~("a", "b")
//│ ╔══[COMPILATION ERROR] Unexpected type annotations ~{ "a"; "b" }
//│ ║ l.35: ~("a", "b")
//│ ║ l.43: ~("a", "b")
//│ ╙── ^^^


:pe
:ge
~ of "a", "b"
//│ ╔══[PARSE ERROR] Expected start of statement in this position; found 'of' keyword instead
//│ ║ l.43: ~ of "a", "b"
//│ ║ l.51: ~ of "a", "b"
//│ ╙── ^^
//│ ╔══[PARSE ERROR] Expected end of input; found literal instead
//│ ║ l.43: ~ of "a", "b"
//│ ║ l.51: ~ of "a", "b"
//│ ╙── ^^^
//│ ═══[COMPILATION ERROR] Unexpected type annotations ~<error>

Expand Down

0 comments on commit 242198a

Please sign in to comment.