Skip to content

Commit 45ab1f1

Browse files
Separate module methods from regular methods
Module definitions were implemented by a `ClassDef` with the `kind` being set to `Mod`, despite the existence of `ModuleDef`. Therefore, a module definition would even have a `ClassSymbol` rather than a `ModuleSymbol`! This commit separates `ModuleDef` from `ClassDef`: modules will be elaborated into `ModuleDef` instead of `ClassDef`, with the `kind` of `Mod` and `ModuleSymbol`. This may break the code generator.
1 parent 6e5b46f commit 45ab1f1

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ extends Importer:
471471
case R(id) =>
472472
val sym = members.getOrElse(id.name, die)
473473
val owner = ctx.outer
474+
val mod = owner.fold(false)(_.isInstanceOf[ModuleSymbol])
474475
val tdf = ctx.nest(N).givenIn:
475476
// * Add type parameters to context
476477
val (tps, newCtx1) = td.typeParams match
@@ -486,7 +487,7 @@ extends Importer:
486487
val r = FlowSymbol(s"‹result of ${sym}", nextUid)
487488
val tdf = TermDefinition(owner, k, sym, pss,
488489
td.signature.orElse(newSignatureTrees.get(id.name)).map(term), b, r,
489-
TermDefFlags.empty)
490+
TermDefFlags(mod))
490491
sym.defn = S(tdf)
491492
tdf
492493
go(sts, tdf :: acc)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module M with {
6363
//│ sign = N
6464
//│ body = S of Ref of x@31
6565
//│ resSym = ‹result of member:foo›@32
66-
//│ flags = ()
66+
//│ flags = (module)
6767
//│ res = Lit of UnitLit of true
6868
//│ res = Lit of UnitLit of true
6969

@@ -299,13 +299,13 @@ fun idMod[T](t: MT[T]): MT[T] = t
299299
//│ FAILURE: Unexpected exception
300300
//│ /!!!\ Uncaught error: scala.NotImplementedError: an implementation is missing
301301
//│ at: scala.Predef$.$qmark$qmark$qmark(Predef.scala:344)
302-
//│ at: hkmc2.semantics.Elaborator$VarianceTraverser.traverseType(Elaborator.scala:707)
303-
//│ at: hkmc2.semantics.Elaborator$Traverser.traverseType$$anonfun$10(Elaborator.scala:749)
302+
//│ at: hkmc2.semantics.Elaborator$VarianceTraverser.traverseType(Elaborator.scala:708)
303+
//│ at: hkmc2.semantics.Elaborator$Traverser.traverseType$$anonfun$10(Elaborator.scala:750)
304304
//│ at: scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
305305
//│ at: scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
306306
//│ at: scala.Option.foreach(Option.scala:437)
307-
//│ at: hkmc2.semantics.Elaborator$Traverser.traverseType(Elaborator.scala:749)
308-
//│ at: hkmc2.semantics.Elaborator.go$4$$anonfun$1$$anonfun$1(Elaborator.scala:659)
307+
//│ at: hkmc2.semantics.Elaborator$Traverser.traverseType(Elaborator.scala:750)
308+
//│ at: hkmc2.semantics.Elaborator.go$4$$anonfun$1$$anonfun$1(Elaborator.scala:660)
309309
//│ at: scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
310310
//│ at: scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
311311

0 commit comments

Comments
 (0)