Skip to content

Commit d81ea62

Browse files
FlandiaYingmanLPTK
authored andcommitted
Enforce rules on functions returning modules
1 parent 20a65e0 commit d81ea62

File tree

14 files changed

+118
-22
lines changed

14 files changed

+118
-22
lines changed

hkmc2/shared/src/main/scala/hkmc2/codegen/js/JSBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class JSBuilder extends CodeBuilder:
187187
} + ")""""
188188
}; }"""
189189
} #} # }"
190-
if clsDefn.kind is syntax.Mod then
190+
if (clsDefn.kind is syntax.Mod) || (clsDefn.kind is syntax.Obj) then
191191
val clsTmp = summon[Scope].allocateName(new semantics.TempSymbol(0/*TODO rm this useless param*/, N, sym.nme+"$"+"class"))
192192
clsDefn.owner match
193193
case S(owner) =>

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

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -521,19 +521,54 @@ extends Importer:
521521
case ((pss, ctx), ps) =>
522522
val (qs, newCtx) = params(ps)(using ctx)
523523
(pss :+ ParamList(ParamListFlags.empty, qs), newCtx)
524+
// * Elaborate signature
525+
val st = td.signature.orElse(newSignatureTrees.get(id.name))
526+
val s = st.map(term(_)(using newCtx))
524527
val b = rhs.map(term(_)(using newCtx))
525528
val r = FlowSymbol(s"‹result of ${sym}", nextUid)
526-
val tdf = TermDefinition(owner, k, sym, pss,
527-
td.signature.orElse(newSignatureTrees.get(id.name)).map(term), b, r,
528-
TermDefFlags(isModMember))
529+
val tdf = TermDefinition(owner, k, sym, pss, s, b, r,
530+
TermDefFlags.empty.copy(isModMember = isModMember))
529531
sym.defn = S(tdf)
532+
533+
// the return type of the function
534+
val result = td.head match
535+
case InfixApp(_, Keyword.`:`, rhs) => S(term(rhs)(using newCtx))
536+
case _ => N
537+
538+
// indicates if the function really returns a module
539+
val em = b.fold(false)(ModuleChecker.evalsToModule)
540+
// indicates if the function marks its result as "module"
541+
val mm = st match
542+
case Some(TypeDef(Mod, _, N, N)) => true
543+
case _ => false
544+
545+
// checks rules regarding module methods
546+
s match
547+
case N if em => raise:
548+
ErrorReport:
549+
msg"Function returning module values must have explicit return types." ->
550+
td.head.toLoc :: Nil
551+
case S(t) if em && ModuleChecker.isTypeParam(t) => raise:
552+
ErrorReport:
553+
msg"Function returning module values must have concrete return types." ->
554+
td.head.toLoc :: Nil
555+
case S(_) if em && !mm => raise:
556+
ErrorReport:
557+
msg"The return type of functions returning module values must be prefixed with module keyword." ->
558+
td.head.toLoc :: Nil
559+
case S(_) if mm && !isModMember => raise:
560+
ErrorReport:
561+
msg"Only module methods may return module values." ->
562+
td.head.toLoc :: Nil
563+
case _ => ()
564+
530565
tdf
531566
go(sts, tdf :: acc)
532567
case L(d) =>
533568
raise(d)
534569
go(sts, acc)
535570
case (td @ TypeDef(k, head, extension, body)) :: sts =>
536-
assert((k is Als) || (k is Cls) || (k is Mod), k)
571+
assert((k is Als) || (k is Cls) || (k is Mod) || (k is Obj), k)
537572
val nme = td.name match
538573
case R(id) => id
539574
case L(d) =>
@@ -585,7 +620,7 @@ extends Importer:
585620
semantics.TypeDef(alsSym, tps, extension.map(term), N)
586621
alsSym.defn = S(d)
587622
d
588-
case Mod =>
623+
case k: (Mod.type | Obj.type) =>
589624
val clsSym = td.symbol.asInstanceOf[ModuleSymbol] // TODO: improve `asInstanceOf`
590625
val owner = ctx.outer
591626
newCtx.nest(S(clsSym)).givenIn:
@@ -596,7 +631,7 @@ extends Importer:
596631
// case S(t) => block(t :: Nil)
597632
case S(t) => ???
598633
case N => (new Term.Blk(Nil, Term.Lit(UnitLit(true))), ctx)
599-
ModuleDef(owner, clsSym, tps, ps, ObjBody(bod))
634+
ModuleDef(owner, clsSym, tps, ps, k, ObjBody(bod))
600635
clsSym.defn = S(cd)
601636
cd
602637
case Cls =>
@@ -620,7 +655,6 @@ extends Importer:
620655
// TODO: pass abstract to `go`
621656
go(body :: sts, acc)
622657
case Modified(Keyword.`declare`, absLoc, body) :: sts =>
623-
???
624658
// TODO: pass declare to `go`
625659
go(body :: sts, acc)
626660
case (result: Tree) :: Nil =>
@@ -725,6 +759,23 @@ extends Importer:
725759
.filter(_.isInstanceOf[VarSymbol])
726760
.flatMap(_.asInstanceOf[VarSymbol].decl)
727761
.fold(false)(_.isInstanceOf[TyParam])
762+
763+
/** Checks if a term evaluates to a module value. */
764+
def evalsToModule(t: Term): Bool =
765+
def isModule(t: Tree): Bool = t match
766+
case TypeDef(Mod, _, _, _) => true
767+
case _ => false
768+
def returnsModule(t: TermDef): Bool = t.signature match
769+
case S(TypeDef(Mod, _, N, N)) => true
770+
case _ => false
771+
t match
772+
case Term.Blk(_, res) => evalsToModule(res)
773+
case Term.App(lhs, rhs) => lhs.symbol match
774+
case S(sym: BlockMemberSymbol) => sym.trmTree.fold(false)(returnsModule)
775+
case _ => false
776+
case t => t.symbol match
777+
case S(sym: BlockMemberSymbol) => sym.modTree.fold(false)(isModule)
778+
case _ => false
728779

729780
class VarianceTraverser(var changed: Bool = true) extends Traverser:
730781
override def traverseType(pol: Pol)(trm: Term): Unit = trm match

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class BlockMemberSymbol(val nme: Str, val trees: Ls[Tree]) extends MemberSymbol[
9696
def clsTree: Opt[Tree.TypeDef] = trees.collectFirst:
9797
case t: Tree.TypeDef if t.k is Cls => t
9898
def modTree: Opt[Tree.TypeDef] = trees.collectFirst:
99-
case t: Tree.TypeDef if t.k is Mod => t
99+
case t: Tree.TypeDef if (t.k is Mod) || (t.k is Obj) => t
100100
def alsTree: Opt[Tree.TypeDef] = trees.collectFirst:
101101
case t: Tree.TypeDef if t.k is Als => t
102102
def trmTree: Opt[Tree.TermDef] = trees.collectFirst:

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,14 @@ sealed abstract class ClassLikeDef extends TypeLikeDef:
238238
val body: ObjBody
239239

240240

241-
case class ModuleDef(owner: Opt[InnerSymbol], sym: ModuleSymbol, tparams: Ls[TyParam], paramsOpt: Opt[Ls[Param]], body: ObjBody) extends ClassLikeDef with Companion:
242-
self =>
243-
val kind: ClsLikeKind = Mod
241+
case class ModuleDef(
242+
owner: Opt[InnerSymbol],
243+
sym: ModuleSymbol,
244+
tparams: Ls[TyParam],
245+
paramsOpt: Opt[Ls[Param]],
246+
kind: ClsLikeKind,
247+
body: ObjBody,
248+
) extends ClassLikeDef with Companion
244249

245250

246251
sealed abstract class ClassDef extends ClassLikeDef:

hkmc2/shared/src/main/scala/hkmc2/syntax/Keyword.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ object Keyword:
9494
val `new` = Keyword("new", N, curPrec) // TODO: check the prec
9595
// val `namespace` = Keyword("namespace", N, N)
9696
val `module` = Keyword("module", N, curPrec)
97+
val `object` = Keyword("object", N, curPrec)
9798
val `open` = Keyword("open", N, curPrec)
9899
val `type` = Keyword("type", N, N)
99100
val `where` = Keyword("where", N, N)

hkmc2/shared/src/main/scala/hkmc2/syntax/ParseRule.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ object ParseRule:
271271
Kw(`class`)(typeDeclBody(Cls)),
272272
Kw(`trait`)(typeDeclBody(Trt)),
273273
Kw(`module`)(typeDeclBody(Mod)),
274+
Kw(`object`)(typeDeclBody(Obj)),
274275
Kw(`open`):
275276
ParseRule("'open' keyword")(
276277
exprOrBlk(ParseRule("'open' declaration")(End(()))){

hkmc2/shared/src/main/scala/hkmc2/syntax/Tree.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ case object Trt extends TypeDefKind("trait") with ObjDefKind
203203
case object Mxn extends TypeDefKind("mixin")
204204
case object Als extends TypeDefKind("type alias")
205205
case object Mod extends TypeDefKind("module") with ClsLikeKind
206+
case object Obj extends TypeDefKind("object") with ClsLikeKind
206207

207208

208209

@@ -275,7 +276,7 @@ trait TypeDefImpl extends TypeOrTermDef:
275276

276277
lazy val symbol = k match
277278
case Cls => semantics.ClassSymbol(this, name.getOrElse(Ident("<error>")))
278-
case Mod => semantics.ModuleSymbol(this, name.getOrElse(Ident("<error>")))
279+
case Mod | Obj => semantics.ModuleSymbol(this, name.getOrElse(Ident("<error>")))
279280
case Als => semantics.TypeAliasSymbol(name.getOrElse(Ident("<error>")))
280281
case Trt | Mxn => ???
281282

hkmc2/shared/src/test/mlscript-compile/Option.mls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ open Predef
99
module Option with ...
1010

1111
class Some(value)
12-
module None
12+
object None
1313

1414
fun isDefined(x) = if x is
1515
Some then true

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,39 @@ fun f2[T](module m: T)
2020
//│ ║ l.18: fun f2[T](module m: T)
2121
//│ ╙── ^^^^
2222

23+
:e
24+
module N with {
25+
fun f3() = M
26+
}
27+
//│ ╔══[ERROR] Function returning module values must have explicit return types.
28+
//│ ║ l.25: fun f3() = M
29+
//│ ╙── ^^^^
30+
31+
:e
32+
module N with {
33+
fun f4[T](): module T = M
34+
}
35+
//│ ╔══[ERROR] Function returning module values must have explicit return types.
36+
//│ ║ l.33: fun f4[T](): module T = M
37+
//│ ╙── ^^^^^^^^^^^^^^^^^
38+
39+
:e
40+
module N with {
41+
fun f5(): M = M
42+
}
43+
//│ ╔══[ERROR] The return type of functions returning module values must be prefixed with module keyword.
44+
//│ ║ l.41: fun f5(): M = M
45+
//│ ╙── ^^^^^^^
46+
47+
:e
48+
fun f7(): module M
49+
//│ ╔══[ERROR] Only module methods may return module values.
50+
//│ ║ l.48: fun f7(): module M
51+
//│ ╙── ^^^^^^^^^^^^^^
52+
2353

2454
fun ok1(module m: M)
55+
56+
module N with {
57+
fun ok2(): module M = M
58+
}

hkmc2/shared/src/test/mlscript/bbml/bbBorrowing.mls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ letreg of r =>
6161
123
6262
if next(it) > 0 then () => 0 else () => clear(b)
6363
k()
64-
//│ /!!!\ Uncaught error: scala.MatchError: Cons(Branch(Ref($scrut@102),Lit(BoolLit(true)),Else(Lam(List(),Lit(IntLit(0))))),Else(Lam(List(),App(Sel(Ref(globalThis:block#5),Ident(clear)),Tup(List(Fld(‹›,Ref(b@91),None))))))) (of class hkmc2.semantics.Split$Cons)
64+
//│ /!!!\ Uncaught error: scala.MatchError: Cons(Branch(Ref($scrut@123),Lit(BoolLit(true)),Else(Lam(List(),Lit(IntLit(0))))),Else(Lam(List(),App(Sel(Ref(globalThis:block#5),Ident(clear)),Tup(List(Fld(‹›,Ref(b@112),None))))))) (of class hkmc2.semantics.Split$Cons)
6565

6666
:e
6767
letreg of r =>

hkmc2/shared/src/test/mlscript/bbml/bbCheck.mls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ high(x => x + 1)
103103

104104
:fixme
105105
(if false then x => x else y => y): [A] -> A -> A
106-
//│ /!!!\ Uncaught error: scala.MatchError: Cons(Branch(Ref($scrut@87),Lit(BoolLit(true)),Else(Lam(List(Param(‹›,x@88,None)),Ref(x@88)))),Else(Lam(List(Param(‹›,y@86,None)),Ref(y@86)))) (of class hkmc2.semantics.Split$Cons)
106+
//│ /!!!\ Uncaught error: scala.MatchError: Cons(Branch(Ref($scrut@88),Lit(BoolLit(true)),Else(Lam(List(Param(‹›,x@89,None)),Ref(x@89)))),Else(Lam(List(Param(‹›,y@87,None)),Ref(y@87)))) (of class hkmc2.semantics.Split$Cons)
107107

108108

109109
fun baz: Int -> (([A] -> A -> A), Int) -> Int

hkmc2/shared/src/test/mlscript/bbml/bbGPCE.mls

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fun power(x) = case
77
0 then `1.0
88
n then x `*. power(x)(n - 1)
99
power
10-
//│ /!!!\ Uncaught error: scala.MatchError: Cons(Branch(Ref(caseScrut@33),Lit(IntLit(0)),Else(Quoted(Lit(DecLit(1.0))))),Let(n@34,Ref(caseScrut@33),Else(Quoted(App(Ref(builtin:*),Tup(List(Fld(‹›,Unquoted(Ref(x@32)),None), Fld(‹›,Unquoted(App(App(Sel(Ref(globalThis:block#0),Ident(power)),Tup(List(Fld(‹›,Ref(x@32),None)))),Tup(List(Fld(‹›,App(Sel(Ref(globalThis:import#bbPredef),Ident(-)),Tup(List(Fld(‹›,Ref(n@34),None), Fld(‹›,Lit(IntLit(1)),None)))),None))))),None)))))))) (of class hkmc2.semantics.Split$Cons)
10+
//│ /!!!\ Uncaught error: scala.MatchError: Cons(Branch(Ref(caseScrut@35),Lit(IntLit(0)),Else(Quoted(Lit(DecLit(1.0))))),Let(n@36,Ref(caseScrut@35),Else(Quoted(App(Ref(builtin:*),Tup(List(Fld(‹›,Unquoted(Ref(x@33)),None), Fld(‹›,Unquoted(App(App(Sel(Ref(globalThis:block#0),Ident(power)),Tup(List(Fld(‹›,Ref(x@33),None)))),Tup(List(Fld(‹›,App(Sel(Ref(globalThis:import#bbPredef),Ident(-)),Tup(List(Fld(‹›,Ref(n@36),None), Fld(‹›,Lit(IntLit(1)),None)))),None))))),None)))))))) (of class hkmc2.semantics.Split$Cons)
1111

1212

1313
fun id: [A] -> A -> A
@@ -57,7 +57,7 @@ fun body(x, y) = case
5757
fun gib_naive(n) =
5858
(x, y) `=> body(x, y)(n)
5959
let gn5 = run(gib_naive(5))
60-
//│ /!!!\ Uncaught error: scala.MatchError: Cons(Branch(Ref(caseScrut@79),Lit(IntLit(0)),Else(Ref(x@77))),Cons(Branch(Ref(caseScrut@79),Lit(IntLit(1)),Else(Ref(y@78))),Let(n@80,Ref(caseScrut@79),Else(App(App(Sel(Ref(globalThis:block#7),Ident(body)),Tup(List(Fld(‹›,Ref(y@78),None), Fld(‹›,Quoted(App(Sel(Ref(globalThis:import#bbPredef),Ident(+)),Tup(List(Fld(‹›,Unquoted(Ref(x@77)),None), Fld(‹›,Unquoted(Ref(y@78)),None))))),None)))),Tup(List(Fld(‹›,App(Sel(Ref(globalThis:import#bbPredef),Ident(-)),Tup(List(Fld(‹›,Ref(n@80),None), Fld(‹›,Lit(IntLit(1)),None)))),None)))))))) (of class hkmc2.semantics.Split$Cons)
60+
//│ /!!!\ Uncaught error: scala.MatchError: Cons(Branch(Ref(caseScrut@88),Lit(IntLit(0)),Else(Ref(x@84))),Cons(Branch(Ref(caseScrut@88),Lit(IntLit(1)),Else(Ref(y@85))),Let(n@89,Ref(caseScrut@88),Else(App(App(Sel(Ref(globalThis:block#7),Ident(body)),Tup(List(Fld(‹›,Ref(y@85),None), Fld(‹›,Quoted(App(Sel(Ref(globalThis:import#bbPredef),Ident(+)),Tup(List(Fld(‹›,Unquoted(Ref(x@84)),None), Fld(‹›,Unquoted(Ref(y@85)),None))))),None)))),Tup(List(Fld(‹›,App(Sel(Ref(globalThis:import#bbPredef),Ident(-)),Tup(List(Fld(‹›,Ref(n@89),None), Fld(‹›,Lit(IntLit(1)),None)))),None)))))))) (of class hkmc2.semantics.Split$Cons)
6161

6262
fun bind(rhs, k) = `let x = rhs `in k(x)
6363
bind
@@ -70,7 +70,7 @@ fun body(x, y) = case
7070
0 then x
7171
1 then y
7272
n then bind of x `+ y, (z => body(y, z)(n - 1)): [C] -> CodeBase[out Int, out C, out Any] -> CodeBase[out C, out Any]
73-
//│ /!!!\ Uncaught error: scala.MatchError: Cons(Branch(Ref(caseScrut@107),Lit(IntLit(0)),Else(Ref(x@105))),Cons(Branch(Ref(caseScrut@107),Lit(IntLit(1)),Else(Ref(y@106))),Let(n@108,Ref(caseScrut@107),Else(App(Sel(Ref(globalThis:block#8),Ident(bind)),Tup(List(Fld(‹›,Quoted(App(Sel(Ref(globalThis:import#bbPredef),Ident(+)),Tup(List(Fld(‹›,Unquoted(Ref(x@105)),None), Fld(‹›,Unquoted(Ref(y@106)),None))))),None), Fld(‹›,Lam(List(Param(‹›,z@111,None)),App(App(Sel(Ref(globalThis:block#9),Ident(body)),Tup(List(Fld(‹›,Ref(y@106),None), Fld(‹›,Ref(z@111),None)))),Tup(List(Fld(‹›,App(Sel(Ref(globalThis:import#bbPredef),Ident(-)),Tup(List(Fld(‹›,Ref(n@108),None), Fld(‹›,Lit(IntLit(1)),None)))),None))))),Some(Forall(List(QuantVar(C@115,None,None)),FunTy(Tup(List(Fld(‹›,TyApp(Sel(Ref(globalThis:import#bbPredef),Ident(CodeBase)),List(WildcardTy(None,Some(Sel(Ref(globalThis:import#Prelude),Ident(Int)))), WildcardTy(None,Some(Ref(C@115))), WildcardTy(None,Some(Sel(Ref(globalThis:import#Prelude),Ident(Any)))))),None))),TyApp(Sel(Ref(globalThis:import#bbPredef),Ident(CodeBase)),List(WildcardTy(None,Some(Ref(C@115))), WildcardTy(None,Some(Sel(Ref(globalThis:import#Prelude),Ident(Any)))))),None))))))))))) (of class hkmc2.semantics.Split$Cons)
73+
//│ /!!!\ Uncaught error: scala.MatchError: Cons(Branch(Ref(caseScrut@116),Lit(IntLit(0)),Else(Ref(x@113))),Cons(Branch(Ref(caseScrut@116),Lit(IntLit(1)),Else(Ref(y@114))),Let(n@117,Ref(caseScrut@116),Else(App(Sel(Ref(globalThis:block#8),Ident(bind)),Tup(List(Fld(‹›,Quoted(App(Sel(Ref(globalThis:import#bbPredef),Ident(+)),Tup(List(Fld(‹›,Unquoted(Ref(x@113)),None), Fld(‹›,Unquoted(Ref(y@114)),None))))),None), Fld(‹›,Lam(List(Param(‹›,z@120,None)),App(App(Sel(Ref(globalThis:block#9),Ident(body)),Tup(List(Fld(‹›,Ref(y@114),None), Fld(‹›,Ref(z@120),None)))),Tup(List(Fld(‹›,App(Sel(Ref(globalThis:import#bbPredef),Ident(-)),Tup(List(Fld(‹›,Ref(n@117),None), Fld(‹›,Lit(IntLit(1)),None)))),None))))),Some(Forall(List(QuantVar(C@124,None,None)),FunTy(Tup(List(Fld(‹›,TyApp(Sel(Ref(globalThis:import#bbPredef),Ident(CodeBase)),List(WildcardTy(None,Some(Sel(Ref(globalThis:import#Prelude),Ident(Int)))), WildcardTy(None,Some(Ref(C@124))), WildcardTy(None,Some(Sel(Ref(globalThis:import#Prelude),Ident(Any)))))),None))),TyApp(Sel(Ref(globalThis:import#bbPredef),Ident(CodeBase)),List(WildcardTy(None,Some(Ref(C@124))), WildcardTy(None,Some(Sel(Ref(globalThis:import#Prelude),Ident(Any)))))),None))))))))))) (of class hkmc2.semantics.Split$Cons)
7474

7575
fun bind: [G] -> (CodeBase[out Int, out G, out Any], [C] -> CodeBase[out Int, out C, out Any] -> CodeBase[out Int, out C | G, out Any]) -> CodeBase[out Int, out G, out Any]
7676
fun bind(rhs, k) = `let x = rhs `in k(x)
@@ -85,7 +85,7 @@ fun body(x, y) = case
8585
1 then y
8686
n then bind of x `+ y, (z => body(y, z)(n - 1)): [C] -> CodeBase[out Int, out C, out Any] -> CodeBase[out Int, out C, out Any]
8787
body
88-
//│ /!!!\ Uncaught error: scala.MatchError: Cons(Branch(Ref(caseScrut@134),Lit(IntLit(0)),Else(Ref(x@132))),Cons(Branch(Ref(caseScrut@134),Lit(IntLit(1)),Else(Ref(y@133))),Let(n@135,Ref(caseScrut@134),Else(App(Sel(Ref(globalThis:block#10),Ident(bind)),Tup(List(Fld(‹›,Quoted(App(Sel(Ref(globalThis:import#bbPredef),Ident(+)),Tup(List(Fld(‹›,Unquoted(Ref(x@132)),None), Fld(‹›,Unquoted(Ref(y@133)),None))))),None), Fld(‹›,Lam(List(Param(‹›,z@138,None)),App(App(Sel(Ref(globalThis:block#11),Ident(body)),Tup(List(Fld(‹›,Ref(y@133),None), Fld(‹›,Ref(z@138),None)))),Tup(List(Fld(‹›,App(Sel(Ref(globalThis:import#bbPredef),Ident(-)),Tup(List(Fld(‹›,Ref(n@135),None), Fld(‹›,Lit(IntLit(1)),None)))),None))))),Some(Forall(List(QuantVar(C@142,None,None)),FunTy(Tup(List(Fld(‹›,TyApp(Sel(Ref(globalThis:import#bbPredef),Ident(CodeBase)),List(WildcardTy(None,Some(Sel(Ref(globalThis:import#Prelude),Ident(Int)))), WildcardTy(None,Some(Ref(C@142))), WildcardTy(None,Some(Sel(Ref(globalThis:import#Prelude),Ident(Any)))))),None))),TyApp(Sel(Ref(globalThis:import#bbPredef),Ident(CodeBase)),List(WildcardTy(None,Some(Sel(Ref(globalThis:import#Prelude),Ident(Int)))), WildcardTy(None,Some(Ref(C@142))), WildcardTy(None,Some(Sel(Ref(globalThis:import#Prelude),Ident(Any)))))),None))))))))))) (of class hkmc2.semantics.Split$Cons)
88+
//│ /!!!\ Uncaught error: scala.MatchError: Cons(Branch(Ref(caseScrut@146),Lit(IntLit(0)),Else(Ref(x@143))),Cons(Branch(Ref(caseScrut@146),Lit(IntLit(1)),Else(Ref(y@144))),Let(n@147,Ref(caseScrut@146),Else(App(Sel(Ref(globalThis:block#10),Ident(bind)),Tup(List(Fld(‹›,Quoted(App(Sel(Ref(globalThis:import#bbPredef),Ident(+)),Tup(List(Fld(‹›,Unquoted(Ref(x@143)),None), Fld(‹›,Unquoted(Ref(y@144)),None))))),None), Fld(‹›,Lam(List(Param(‹›,z@150,None)),App(App(Sel(Ref(globalThis:block#11),Ident(body)),Tup(List(Fld(‹›,Ref(y@144),None), Fld(‹›,Ref(z@150),None)))),Tup(List(Fld(‹›,App(Sel(Ref(globalThis:import#bbPredef),Ident(-)),Tup(List(Fld(‹›,Ref(n@147),None), Fld(‹›,Lit(IntLit(1)),None)))),None))))),Some(Forall(List(QuantVar(C@154,None,None)),FunTy(Tup(List(Fld(‹›,TyApp(Sel(Ref(globalThis:import#bbPredef),Ident(CodeBase)),List(WildcardTy(None,Some(Sel(Ref(globalThis:import#Prelude),Ident(Int)))), WildcardTy(None,Some(Ref(C@154))), WildcardTy(None,Some(Sel(Ref(globalThis:import#Prelude),Ident(Any)))))),None))),TyApp(Sel(Ref(globalThis:import#bbPredef),Ident(CodeBase)),List(WildcardTy(None,Some(Sel(Ref(globalThis:import#Prelude),Ident(Int)))), WildcardTy(None,Some(Ref(C@154))), WildcardTy(None,Some(Sel(Ref(globalThis:import#Prelude),Ident(Any)))))),None))))))))))) (of class hkmc2.semantics.Split$Cons)
8989

9090
fun gib(n) = (x, y) `=> body(x, y)(n)
9191
let g5 = run(gib(5))

hkmc2/shared/src/test/mlscript/bbml/bbTODOs.mls

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ fun id[A](x: A) = x
2020
fun id: [A] -> A -> A => x = x
2121
//│ ╔══[ERROR] Name not found: x
2222
//│ ║ l.20: fun id: [A] -> A -> A => x = x
23+
//│ ╙── ^
24+
//│ ╔══[ERROR] Name not found: x
25+
//│ ║ l.20: fun id: [A] -> A -> A => x = x
2326
//│ ╙── ^
2427
//│ ╔══[ERROR] Name not found: x
2528
//│ ║ l.20: fun id: [A] -> A -> A => x = x
2629
//│ ╙── ^
27-
//│ /!!!\ Uncaught error: scala.MatchError: Lam(List(Param(‹›,A@37,None)),Error) (of class hkmc2.semantics.Term$Lam)
30+
//│ /!!!\ Uncaught error: scala.MatchError: Lam(List(Param(‹›,A@36,None)),Error) (of class hkmc2.semantics.Term$Lam)
2831

2932

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ M.oops
9494

9595
:sjs
9696
module M with
97-
val m = M
97+
val m: module M = M
9898
//│ JS:
9999
//│ const M$class = class M {
100100
//│ constructor() {

0 commit comments

Comments
 (0)