Skip to content

Commit 9659ced

Browse files
Separate module results from regular results
1 parent fbb624d commit 9659ced

File tree

3 files changed

+14
-84
lines changed

3 files changed

+14
-84
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ extends Importer:
271271
Term.Ret(term(body))
272272
case Modified(Keyword.`do`, kwLoc, body) =>
273273
Term.Blk(term(body) :: Nil, unit)
274+
case TypeDef(Mod, head, N, N) =>
275+
term(head)
274276
case Tree.Region(id: Tree.Ident, body) =>
275277
val sym = VarSymbol(id, nextUid)
276278
val nestCtx = ctx + (id.name -> sym)
@@ -325,7 +327,11 @@ extends Importer:
325327
def fld(tree: Tree): Ctxl[Fld] = tree match
326328
case InfixApp(lhs, Keyword.`:`, rhs) =>
327329
Fld(FldFlags.empty, term(lhs), S(term(rhs)))
328-
case _ => Fld(FldFlags.empty, term(tree), N)
330+
case _ =>
331+
val t = term(tree)
332+
t.symbol.flatMap(_.asMod) match
333+
case S(_) => Fld(FldFlags.empty.copy(mod = true), t, N)
334+
case N => Fld(FldFlags.empty, t, N)
329335

330336
def unit: Term.Lit = Term.Lit(UnitLit(true))
331337

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ object Keyword:
9090
val `super` = Keyword("super", N, N)
9191
val `new` = Keyword("new", N, curPrec) // TODO: check the prec
9292
// val `namespace` = Keyword("namespace", N, N)
93-
val `module` = Keyword("module", N, N)
93+
val `module` = Keyword("module", N, curPrec)
9494
val `open` = Keyword("open", N, curPrec)
9595
val `type` = Keyword("type", N, N)
9696
val `where` = Keyword("where", N, N)

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

Lines changed: 6 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ module M with {
99
// module method self that returns itself
1010
fun self(): module M = M
1111
}
12-
//│ FAILURE: Unexpected exception
13-
//│ /!!!\ Uncaught error: java.lang.Exception: Internal Error: keyword 'module' does not have right precedence
14-
//│ at: mlscript.utils.package$.lastWords(package.scala:211)
15-
//│ at: hkmc2.syntax.Keyword.assumeRightPrec$$anonfun$1(Keyword.scala:31)
16-
//│ at: scala.Option.getOrElse(Option.scala:201)
17-
//│ at: hkmc2.syntax.Keyword.assumeRightPrec(Keyword.scala:31)
18-
//│ at: hkmc2.syntax.Parser.parseRuleImpl(Parser.scala:351)
19-
//│ at: hkmc2.syntax.Parser.parseRule$$anonfun$2(Parser.scala:321)
20-
//│ at: hkmc2.syntax.Parser.wrap(Parser.scala:129)
21-
//│ at: hkmc2.syntax.Parser.parseRule(Parser.scala:321)
22-
//│ at: hkmc2.syntax.Parser.expr(Parser.scala:460)
23-
//│ at: hkmc2.syntax.Parser.exprContImpl(Parser.scala:921)
2412

2513
:e
2614
fun f1(module m)
@@ -34,106 +22,42 @@ fun f2[T](module m: T)
3422
module N with {
3523
fun f3(): M = M
3624
}
37-
//│ ╔══[ERROR] Name not found: M
38-
//│ ║ l.35: fun f3(): M = M
39-
//│ ╙── ^
40-
//│ ╔══[ERROR] Name not found: M
41-
//│ ║ l.35: fun f3(): M = M
42-
//│ ╙── ^
25+
//│ FAILURE: Unexpected lack of type error
4326

4427
:e
4528
module N with {
4629
fun f4[T](): module T = M
4730
}
48-
//│ FAILURE: Unexpected exception
49-
//│ /!!!\ Uncaught error: java.lang.Exception: Internal Error: keyword 'module' does not have right precedence
50-
//│ at: mlscript.utils.package$.lastWords(package.scala:211)
51-
//│ at: hkmc2.syntax.Keyword.assumeRightPrec$$anonfun$1(Keyword.scala:31)
52-
//│ at: scala.Option.getOrElse(Option.scala:201)
53-
//│ at: hkmc2.syntax.Keyword.assumeRightPrec(Keyword.scala:31)
54-
//│ at: hkmc2.syntax.Parser.parseRuleImpl(Parser.scala:351)
55-
//│ at: hkmc2.syntax.Parser.parseRule$$anonfun$2(Parser.scala:321)
56-
//│ at: hkmc2.syntax.Parser.wrap(Parser.scala:129)
57-
//│ at: hkmc2.syntax.Parser.parseRule(Parser.scala:321)
58-
//│ at: hkmc2.syntax.Parser.expr(Parser.scala:460)
59-
//│ at: hkmc2.syntax.Parser.exprContImpl(Parser.scala:921)
31+
//│ FAILURE: Unexpected lack of type error
6032

6133
:e
6234
module N with {
6335
fun f5(): M = M
6436
}
65-
//│ ╔══[ERROR] Name not found: M
66-
//│ ║ l.63: fun f5(): M = M
67-
//│ ╙── ^
68-
//│ ╔══[ERROR] Name not found: M
69-
//│ ║ l.63: fun f5(): M = M
70-
//│ ╙── ^
37+
//│ FAILURE: Unexpected lack of type error
7138

7239

7340
fun f6(m: M)
74-
//│ FAILURE: Unexpected type error
75-
//│ ╔══[ERROR] Name not found: M
76-
//│ ║ l.73: fun f6(m: M)
77-
//│ ╙── ^
7841

7942
:e
8043
f6(M)
81-
//│ ╔══[ERROR] Name not found: M
82-
//│ ║ l.80: f6(M)
83-
//│ ╙── ^
44+
//│ FAILURE: Unexpected lack of type error
8445

8546
:e
8647
f6(M.self())
87-
//│ ╔══[ERROR] Name not found: M
88-
//│ ║ l.86: f6(M.self())
89-
//│ ╙── ^
48+
//│ FAILURE: Unexpected lack of type error
9049

9150
:e
9251
fun f7(): module M
93-
//│ FAILURE: Unexpected exception
94-
//│ /!!!\ Uncaught error: java.lang.Exception: Internal Error: keyword 'module' does not have right precedence
95-
//│ at: mlscript.utils.package$.lastWords(package.scala:211)
96-
//│ at: hkmc2.syntax.Keyword.assumeRightPrec$$anonfun$1(Keyword.scala:31)
97-
//│ at: scala.Option.getOrElse(Option.scala:201)
98-
//│ at: hkmc2.syntax.Keyword.assumeRightPrec(Keyword.scala:31)
99-
//│ at: hkmc2.syntax.Parser.parseRuleImpl(Parser.scala:351)
100-
//│ at: hkmc2.syntax.Parser.parseRule$$anonfun$2(Parser.scala:321)
101-
//│ at: hkmc2.syntax.Parser.wrap(Parser.scala:129)
102-
//│ at: hkmc2.syntax.Parser.parseRule(Parser.scala:321)
103-
//│ at: hkmc2.syntax.Parser.expr(Parser.scala:460)
104-
//│ at: hkmc2.syntax.Parser.exprContImpl(Parser.scala:921)
52+
//│ FAILURE: Unexpected lack of type error
10553

10654

10755
fun ok1(module m: M)
108-
//│ FAILURE: Unexpected type error
109-
//│ ╔══[ERROR] Name not found: M
110-
//│ ║ l.107: fun ok1(module m: M)
111-
//│ ╙── ^
11256

11357
module N with {
11458
fun ok2(): module M = M
11559
}
116-
//│ FAILURE: Unexpected exception
117-
//│ /!!!\ Uncaught error: java.lang.Exception: Internal Error: keyword 'module' does not have right precedence
118-
//│ at: mlscript.utils.package$.lastWords(package.scala:211)
119-
//│ at: hkmc2.syntax.Keyword.assumeRightPrec$$anonfun$1(Keyword.scala:31)
120-
//│ at: scala.Option.getOrElse(Option.scala:201)
121-
//│ at: hkmc2.syntax.Keyword.assumeRightPrec(Keyword.scala:31)
122-
//│ at: hkmc2.syntax.Parser.parseRuleImpl(Parser.scala:351)
123-
//│ at: hkmc2.syntax.Parser.parseRule$$anonfun$2(Parser.scala:321)
124-
//│ at: hkmc2.syntax.Parser.wrap(Parser.scala:129)
125-
//│ at: hkmc2.syntax.Parser.parseRule(Parser.scala:321)
126-
//│ at: hkmc2.syntax.Parser.expr(Parser.scala:460)
127-
//│ at: hkmc2.syntax.Parser.exprContImpl(Parser.scala:921)
12860

12961
ok1(M)
130-
//│ FAILURE: Unexpected type error
131-
//│ ╔══[ERROR] Name not found: M
132-
//│ ║ l.129: ok1(M)
133-
//│ ╙── ^
13462

13563
ok1(M.self())
136-
//│ FAILURE: Unexpected type error
137-
//│ ╔══[ERROR] Name not found: M
138-
//│ ║ l.135: ok1(M.self())
139-
//│ ╙── ^

0 commit comments

Comments
 (0)