Skip to content

Commit 424b104

Browse files
Funny test cases
1 parent 452f81a commit 424b104

File tree

5 files changed

+121
-79
lines changed

5 files changed

+121
-79
lines changed
Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,49 @@
11
:js
2-
// :de
3-
// :sjs
4-
// :pt
5-
// :elt
62

7-
:global
8-
:d
9-
:todo
103

4+
class Foo with
5+
val x = 10
6+
fun foo = x + 1
117

8+
data class Bar(y) extends Foo with
9+
fun bar = y + 1
1210

11+
:dr
12+
data class Baz(z) extends Bar(z * 1) with
13+
fun baz = this.bar * 2
14+
//│ Traversing block: Blk(List(Parameterized(None,Cls,class:Baz‹715›,member:Baz‹714›,List(),ParamList(‹›,List(Param(‹val›,z‹717›,None,Modulefulness(None))),None),Some(New(SynthSel(Ref(member:Bar‹702›),Ident(class)),List(App(Ref(builtin:*‹21›),Tup(List(Fld(‹›,Ref(z‹717›),None), Fld(‹›,Lit(IntLit(1)),None))))),None)),( ‹method› val member:z‹718› = z‹717›#0; ‹method› fun member:baz‹713› = builtin:*‹21›#0(class:Baz‹715›#0.bar, 2)‹builtin:*‹21››; ),None,List(Modifier(keyword 'data')))),Lit(UnitLit(false)))
15+
//│ | Traversing statement: Parameterized(None,Cls,class:Baz‹715›,member:Baz‹714›,List(),ParamList(‹›,List(Param(‹val›,z‹717›,None,Modulefulness(None))),None),Some(New(SynthSel(Ref(member:Bar‹702›),Ident(class)),List(App(Ref(builtin:*‹21›),Tup(List(Fld(‹›,Ref(z‹717›),None), Fld(‹›,Lit(IntLit(1)),None))))),None)),( ‹method› val member:z‹718› = z‹717›#0; ‹method› fun member:baz‹713› = builtin:*‹21›#0(class:Baz‹715›#0.bar, 2)‹builtin:*‹21››; ),None,List(Modifier(keyword 'data')))
16+
//│ | Resolving definition: Parameterized(None,Cls,class:Baz‹715›,member:Baz‹714›,List(),ParamList(‹›,List(Param(‹val›,z‹717›,None,Modulefulness(None))),None),Some(New(SynthSel(Ref(member:Bar‹702›),Ident(class)),List(App(Ref(builtin:*‹21›),Tup(List(Fld(‹›,Ref(z‹717›),None), Fld(‹›,Lit(IntLit(1)),None))))),None)),( ‹method› val member:z‹718› = z‹717›#0; ‹method› fun member:baz‹713› = builtin:*‹21›#0(class:Baz‹715›#0.bar, 2)‹builtin:*‹21››; ),None,List(Modifier(keyword 'data')))
17+
//│ | | Resolving class definition Parameterized(None,Cls,class:Baz‹715›,member:Baz‹714›,List(),ParamList(‹›,List(Param(‹val›,z‹717›,None,Modulefulness(None))),None),Some(New(SynthSel(Ref(member:Bar‹702›),Ident(class)),List(App(Ref(builtin:*‹21›),Tup(List(Fld(‹›,Ref(z‹717›),None), Fld(‹›,Lit(IntLit(1)),None))))),None)),( ‹method› val member:z‹718› = z‹717›#0; ‹method› fun member:baz‹713› = builtin:*‹21›#0(class:Baz‹715›#0.bar, 2)‹builtin:*‹21››; ),None,List(Modifier(keyword 'data')))
18+
//│ | | Resolving parameter ‹val›z‹717›
19+
//│ | | Traversing block: Blk(List(TermDefinition(Some(class:Baz‹715›),ImmutVal,member:z‹718›,List(),None,None,Some(Ref(z‹717›)),‹class-param-res›‹719›,‹method›,Modulefulness(None),List()), TermDefinition(Some(class:Baz‹715›),Fun,member:baz‹713›,List(),None,None,Some(App(Ref(builtin:*‹21›),Tup(List(Fld(‹›,Sel(Ref(class:Baz‹715›),Ident(bar)),None), Fld(‹›,Lit(IntLit(2)),None))))),‹result of member:baz‹713››‹722›,‹method›,Modulefulness(None),List())),Lit(UnitLit(false)))
20+
//│ | | | Traversing statement: TermDefinition(Some(class:Baz‹715›),ImmutVal,member:z‹718›,List(),None,None,Some(Ref(z‹717›)),‹class-param-res›‹719›,‹method›,Modulefulness(None),List())
21+
//│ | | | Resolving definition: TermDefinition(Some(class:Baz‹715›),ImmutVal,member:z‹718›,List(),None,None,Some(Ref(z‹717›)),‹class-param-res›‹719›,‹method›,Modulefulness(None),List())
22+
//│ | | | | Resolving value definition TermDefinition(Some(class:Baz‹715›),ImmutVal,member:z‹718›,List(),None,None,Some(Ref(z‹717›)),‹class-param-res›‹719›,‹method›,Modulefulness(None),List())
23+
//│ | | | | Traversing term: Ref(z‹717›)
24+
//│ | | | | | Resolving resolvable term: Ref(z‹717›), (inPrefix = false)
25+
//│ | | | | | | Resolving with defn = None
26+
//│ | | | | | ~> Ref(z‹717›)
27+
//│ | | | Traversing statement: TermDefinition(Some(class:Baz‹715›),Fun,member:baz‹713›,List(),None,None,Some(App(Ref(builtin:*‹21›),Tup(List(Fld(‹›,Sel(Ref(class:Baz‹715›),Ident(bar)),None), Fld(‹›,Lit(IntLit(2)),None))))),‹result of member:baz‹713››‹722›,‹method›,Modulefulness(None),List())
28+
//│ | | | Resolving definition: TermDefinition(Some(class:Baz‹715›),Fun,member:baz‹713›,List(),None,None,Some(App(Ref(builtin:*‹21›),Tup(List(Fld(‹›,Sel(Ref(class:Baz‹715›),Ident(bar)),None), Fld(‹›,Lit(IntLit(2)),None))))),‹result of member:baz‹713››‹722›,‹method›,Modulefulness(None),List())
29+
//│ | | | | Resolving function definition TermDefinition(Some(class:Baz‹715›),Fun,member:baz‹713›,List(),None,None,Some(App(Ref(builtin:*‹21›),Tup(List(Fld(‹›,Sel(Ref(class:Baz‹715›),Ident(bar)),None), Fld(‹›,Lit(IntLit(2)),None))))),‹result of member:baz‹713››‹722›,‹method›,Modulefulness(None),List())
30+
//│ | | | | Traversing term: App(Ref(builtin:*‹21›),Tup(List(Fld(‹›,Sel(Ref(class:Baz‹715›),Ident(bar)),None), Fld(‹›,Lit(IntLit(2)),None))))
31+
//│ | | | | | Resolving resolvable term: App(Ref(builtin:*‹21›),Tup(List(Fld(‹›,Sel(Ref(class:Baz‹715›),Ident(bar)),None), Fld(‹›,Lit(IntLit(2)),None)))), (inPrefix = false)
32+
//│ | | | | | | Resolving resolvable term: Ref(builtin:*‹21›), (inPrefix = false)
33+
//│ | | | | | | | Resolving with defn = None
34+
//│ | | | | | | ~> Ref(builtin:*‹21›)
35+
//│ | | | | | | Resolving with defn = None
36+
//│ | | | | | | Traversing term: Tup(List(Fld(‹›,Sel(Ref(class:Baz‹715›),Ident(bar)),None), Fld(‹›,Lit(IntLit(2)),None)))
37+
//│ | | | | | | | Traversing term: Sel(Ref(class:Baz‹715›),Ident(bar))
38+
//│ | | | | | | | | Resolving resolvable term: Sel(Ref(class:Baz‹715›),Ident(bar)), (inPrefix = false)
39+
//│ | | | | | | | | | Traversing term: Ref(class:Baz‹715›)
40+
//│ | | | | | | | | | | Resolving resolvable term: Ref(class:Baz‹715›), (inPrefix = false)
41+
//│ | | | | | | | | | | | Resolving with defn = None
42+
//│ | | | | | | | | | | ~> Ref(class:Baz‹715›)
43+
//│ | | | | | | | | | Resolving symbol for Sel(Ref(class:Baz‹715›),Ident(bar)), defn = Some(Parameterized(None,Cls,class:Baz‹715›,member:Baz‹714›,List(),ParamList(‹›,List(Param(‹val›,z‹717›,None,Modulefulness(None))),None),Some(New(SynthSel(Ref(member:Bar‹702›),Ident(class)),List(App(Ref(builtin:*‹21›),Tup(List(Fld(‹›,Ref(z‹717›),None), Fld(‹›,Lit(IntLit(1)),None))))),None)),( ‹method› val member:z‹718› = z‹717›#0; ‹method› fun member:baz‹713› = builtin:*‹21›#0(class:Baz‹715›#0.bar, 2)‹builtin:*‹21››; ),None,List(Modifier(keyword 'data'))))
44+
//│ | | | | | | | | | Resolving with defn = None
45+
//│ | | | | | | | | ~> Sel(Ref(class:Baz‹715›),Ident(bar))
46+
//│ | | | | | | | Traversing term: Lit(IntLit(2))
47+
//│ | | | | | ~> App(Ref(builtin:*‹21›),Tup(List(Fld(‹›,Sel(Ref(class:Baz‹715›),Ident(bar)),None), Fld(‹›,Lit(IntLit(2)),None))))
48+
//│ | | | Traversing term: Lit(UnitLit(false))
49+
//│ | Traversing term: Lit(UnitLit(false))

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

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -113,53 +113,12 @@ id of ({ x: 1, y: 2 })
113113
id of (x: 1, y: 2)
114114
//│ = {x: 1, y: 2}
115115

116+
// * FIXME: handling of record arguments in resolver/checker
117+
:fixme
116118
id of { x: 1, y: 2 }
119+
//│ ╔══[ERROR] Expected 1 arguments, got 2
120+
//│ ║ l.118: id of { x: 1, y: 2 }
121+
//│ ╙── ^^^^^^^^^^
117122
//│ = {x: 1, y: 2}
118123

119124

120-
121-
:silent
122-
import "../../mlscript-compile/Iter.mls"
123-
let graphics = new Set of tuple of
124-
"circle", "ellipse", "image", "line", "path"
125-
"polygon", "polyline", "rect", "text", "use"
126-
127-
fun showProps(x, y, props) = Object.entries(props)
128-
Iter.mapping of case
129-
["x", x'] then "x: " + (x + x')
130-
["y", y'] then "y: " + (y + y')
131-
[k, v] then k + ": " + v
132-
Iter.joined(", ")
133-
134-
fun output(i, s) = print of " ".repeat(i) + s
135-
136-
fun t(kind, props) =
137-
if graphics.has(kind) then
138-
(args) => output of args.i, kind + " " + showProps(args.x, args.y, props)
139-
else
140-
(...children) => (args) =>
141-
output of args.i, kind + " " + showProps(args.x, args.y, props) + " with"
142-
children Iter.each of child => child of
143-
x: args.x + props.x
144-
y: args.y + props.y
145-
i: args.i + 1
146-
147-
let display = t("group", x: 20, y: 20) of
148-
t("circle", x: 30, y: 30, r: 42)
149-
t("rect", x: 40, y: 40, width: 80, height: 90)
150-
t("ellipse", x: 50, y: 50, rx: 40, ry: 60)
151-
//│ display = [function]
152-
153-
display(x: 11, y: 22, i: 2)
154-
//│ > group x: 31, y: 42 with
155-
//│ > circle x: 61, y: 72, r: 42
156-
//│ > rect x: 71, y: 82, width: 80, height: 90
157-
//│ > ellipse x: 81, y: 92, rx: 40, ry: 60
158-
159-
let display = t("group", x: 0, y: 0) of
160-
t("circle", x: 10, y: 10, r: 42)
161-
//│ display = [function]
162-
163-
display(x: 88, y: 99, i: 0)
164-
//│ > group x: 88, y: 99 with
165-
//│ > circle x: 98, y: 109, r: 42

hkmc2/shared/src/test/mlscript/codegen/FunnyOpen.mls

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ open Mod { print, |> }
6464

6565
:fixme
6666
12 |> print
67+
//│ ╔══[ERROR] Module 'Mod' does not contain member '|>'
68+
//│ ║ l.66: 12 |> print
69+
//│ ╙── ^^
6770
//│ ═══[RUNTIME ERROR] TypeError: Mod1.|> is not a function
6871

6972

hkmc2/shared/src/test/mlscript/codegen/ImportMLs.mls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ Some(1)
4848

4949
:re
5050
new Some(1) isDefined()
51-
//│ ═══[RUNTIME ERROR] TypeError: tmp5 is not a constructor
51+
//│ ═══[RUNTIME ERROR] TypeError: tmp5.class is not a constructor
5252

5353
:re
5454
new Some(1)
5555
isDefined()
56-
//│ ═══[RUNTIME ERROR] TypeError: tmp7 is not a constructor
56+
//│ ═══[RUNTIME ERROR] TypeError: tmp7.class is not a constructor
5757

5858

5959
open Option { Some, None, isDefined }

hkmc2/shared/src/test/mlscript/ctx/CascadingTypeClasses.mls

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,72 @@ fun foo[A](using Foo[A], A)
1111
use Foo[Baz] = new Foo
1212

1313

14-
:todo
14+
// FIXME: error message refers to `A`
15+
:e
16+
:fixme // Internal Error should never reach users
1517
foo[Baz]
1618
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
17-
//│ ║ l.15: foo[Baz]
19+
//│ ║ l.17: foo[Baz]
20+
//│ ║ ^^^^^^^
21+
//│ ╟── Required by contextual parameter declaration:
22+
//│ ║ l.9: fun foo[A](using Foo[A], A)
23+
//│ ║ ^
24+
//│ ╙── Expected: A; Available: (Foo[Baz])
25+
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
26+
27+
:e
28+
:fixme // Internal Error should never reach users
29+
foo
30+
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
31+
//│ ║ l.29: foo
1832
//│ ║ ^^^
1933
//│ ╟── Required by contextual parameter declaration:
2034
//│ ║ l.9: fun foo[A](using Foo[A], A)
2135
//│ ║ ^
22-
//│ ╙── Expected: A; Available: Map(Sym(class:Foo) -> List((App(Sym(class:Foo),List(Sym(class:Baz))),Instance(member:instance$App(Ident(Foo),TyTup(List(Ident(Baz))))))))
23-
//│ /!!!\ Uncaught error: java.lang.Exception: Internal Error: Found unpopulated contextual argument: CtxArg(None).
36+
//│ ╙── Expected: A; Available: (Foo[Baz])
37+
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
38+
39+
40+
use Baz = new Baz
2441

2542
:todo
2643
foo
2744
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
28-
//│ ║ l.26: foo
45+
//│ ║ l.43: foo
2946
//│ ║ ^^^
3047
//│ ╟── Required by contextual parameter declaration:
3148
//│ ║ l.9: fun foo[A](using Foo[A], A)
3249
//│ ║ ^
33-
//│ ╙── Expected: A; Available: Map(Sym(class:Foo) -> List((App(Sym(class:Foo),List(Sym(class:Baz))),Instance(member:instance$App(Ident(Foo),TyTup(List(Ident(Baz))))))))
34-
//│ /!!!\ Uncaught error: java.lang.Exception: Internal Error: Found unpopulated contextual argument: CtxArg(None).
50+
//│ ╙── Expected: A; Available: (Foo[Baz], Baz)
51+
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
3552

3653

3754
fun foo[A](using Foo[A])(using A)
3855

3956
:todo
4057
foo
4158
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
42-
//│ ║ l.40: foo
59+
//│ ║ l.57: foo
4360
//│ ║ ^^^
4461
//│ ╟── Required by contextual parameter declaration:
45-
//│ ║ l.37: fun foo[A](using Foo[A])(using A)
62+
//│ ║ l.54: fun foo[A](using Foo[A])(using A)
4663
//│ ║ ^
47-
//│ ╙── Expected: A; Available: Map(Sym(class:Foo) -> List((App(Sym(class:Foo),List(Sym(class:Baz))),Instance(member:instance$App(Ident(Foo),TyTup(List(Ident(Baz))))))))
48-
//│ /!!!\ Uncaught error: java.lang.Exception: Internal Error: Found unpopulated contextual argument: CtxArg(None).
64+
//│ ╙── Expected: A; Available: (Foo[Baz], Baz)
65+
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
4966

5067

5168
fun foo[A](using A)(using Foo[A])
5269

5370
:todo
5471
foo
5572
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
56-
//│ ║ l.54: foo
73+
//│ ║ l.71: foo
5774
//│ ║ ^^^
5875
//│ ╟── Required by contextual parameter declaration:
59-
//│ ║ l.51: fun foo[A](using A)(using Foo[A])
76+
//│ ║ l.68: fun foo[A](using A)(using Foo[A])
6077
//│ ║ ^
61-
//│ ╙── Expected: A; Available: Map(Sym(class:Foo) -> List((App(Sym(class:Foo),List(Sym(class:Baz))),Instance(member:instance$App(Ident(Foo),TyTup(List(Ident(Baz))))))))
62-
//│ /!!!\ Uncaught error: java.lang.Exception: Internal Error: Found unpopulated contextual argument: CtxArg(None).
78+
//│ ╙── Expected: A; Available: (Foo[Baz], Baz)
79+
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
6380

6481

6582
use Foo[Bar[Baz]] = new Foo
@@ -68,25 +85,51 @@ use Foo[Bar[Baz]] = new Foo
6885
:e
6986
foo
7087
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
71-
//│ ║ l.69: foo
88+
//│ ║ l.86: foo
7289
//│ ║ ^^^
7390
//│ ╟── Required by contextual parameter declaration:
74-
//│ ║ l.51: fun foo[A](using A)(using Foo[A])
91+
//│ ║ l.68: fun foo[A](using A)(using Foo[A])
7592
//│ ║ ^
76-
//│ ╙── Expected: A; Available: Map(Sym(class:Foo) -> List((App(Sym(class:Foo),List(App(Sym(class:Bar),List(Sym(class:Baz))))),Instance(member:instance$App(Ident(Foo),TyTup(List(App(Ident(Bar),TyTup(List(Ident(Baz))))))))), (App(Sym(class:Foo),List(Sym(class:Baz))),Instance(member:instance$App(Ident(Foo),TyTup(List(Ident(Baz))))))))
77-
//│ /!!!\ Uncaught error: java.lang.Exception: Internal Error: Found unpopulated contextual argument: CtxArg(None).
93+
//│ ╙── Expected: A; Available: (Foo[Bar[Baz]], Foo[Baz], Baz)
94+
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
7895

7996
use Bar[Baz] = new Bar
8097

81-
:todo
98+
:fixme
8299
foo
83100
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
84-
//│ ║ l.82: foo
101+
//│ ║ l.99: foo
85102
//│ ║ ^^^
86103
//│ ╟── Required by contextual parameter declaration:
87-
//│ ║ l.51: fun foo[A](using A)(using Foo[A])
104+
//│ ║ l.68: fun foo[A](using A)(using Foo[A])
105+
//│ ║ ^
106+
//│ ╙── Expected: A; Available: (Foo[Bar[Baz]], Foo[Baz], Baz, Bar[Baz])
107+
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
108+
109+
use Bar[Int] = new Bar
110+
111+
:fixme
112+
foo
113+
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
114+
//│ ║ l.112: foo
115+
//│ ║ ^^^
116+
//│ ╟── Required by contextual parameter declaration:
117+
//│ ║ l.68: fun foo[A](using A)(using Foo[A])
118+
//│ ║ ^
119+
//│ ╙── Expected: A; Available: (Foo[Bar[Baz]], Foo[Baz], Baz, Bar[Int], Bar[Baz])
120+
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
121+
122+
use Bar[Baz] = new Bar
123+
124+
:todo
125+
foo
126+
//│ ╔══[ERROR] Missing instance for contextual parameter of type `A` in this call
127+
//│ ║ l.125: foo
128+
//│ ║ ^^^
129+
//│ ╟── Required by contextual parameter declaration:
130+
//│ ║ l.68: fun foo[A](using A)(using Foo[A])
88131
//│ ║ ^
89-
//│ ╙── Expected: A; Available: Map(Sym(class:Foo) -> List((App(Sym(class:Foo),List(App(Sym(class:Bar),List(Sym(class:Baz))))),Instance(member:instance$App(Ident(Foo),TyTup(List(App(Ident(Bar),TyTup(List(Ident(Baz))))))))), (App(Sym(class:Foo),List(Sym(class:Baz))),Instance(member:instance$App(Ident(Foo),TyTup(List(Ident(Baz))))))), Sym(class:Bar) -> List((App(Sym(class:Bar),List(Sym(class:Baz))),Instance(member:instance$App(Ident(Bar),TyTup(List(Ident(Baz))))))))
90-
//│ /!!!\ Uncaught error: java.lang.Exception: Internal Error: Found unpopulated contextual argument: CtxArg(None).
132+
//│ ╙── Expected: A; Available: (Foo[Bar[Baz]], Foo[Baz], Baz, Bar[Baz], Bar[Int], Bar[Baz])
133+
//│ /!!!\ Uncaught error: hkmc2.InternalError: Not in scope: member:foo (class hkmc2.semantics.BlockMemberSymbol)
91134

92135

0 commit comments

Comments
 (0)