Skip to content

Commit 0c7f3be

Browse files
committed
Allow let to bind capitalized unapplied identifiers
1 parent 0c89194 commit 0c7f3be

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
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
@@ -833,7 +833,8 @@ extends Importer:
833833
newCtx.givenIn:
834834
go(sts, funs, Nil, newAcc)
835835

836-
case (hd @ LetLike(`let`, Apps(id: Ident, tups), rhso, N)) :: sts if id.name.headOption.exists(_.isLower) =>
836+
case (hd @ LetLike(`let`, Apps(id: Ident, tups), rhso, N)) :: sts
837+
if tups.isEmpty || id.name.headOption.exists(_.isLower) =>
837838
val sym =
838839
fieldOrVarSym(LetBind, id)
839840
log(s"Processing `let` statement $id (${sym}) ${ctx.outer}")

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ MyClass
1111
new MyClass("Bob")
1212
//│ = [object Object]
1313

14-
:todo
1514
let C = MyClass
16-
//│ ╔══[ERROR] Unsupported let binding shape
17-
//│ ║ l.15: let C = MyClass
18-
//│ ╙── ^^^^^^^^^^^
15+
//│ C = class MyClass { constructor(name) { this.name = name; } greet() { console.log(`Hello from ${this.name}!`); }}
1916

20-
let c = MyClass
17+
let c = C
2118
//│ c = class MyClass { constructor(name) { this.name = name; } greet() { console.log(`Hello from ${this.name}!`); }}
2219

2320
:todo
@@ -33,7 +30,7 @@ fun foo() =
3330
import "../../js/MyClass.mjs"
3431
()
3532
//│ ╔══[COMPILATION ERROR] Imports must be at the top level
36-
//│ ║ l.33: import "../../js/MyClass.mjs"
33+
//│ ║ l.30: import "../../js/MyClass.mjs"
3734
//│ ╙── ^^^^^^^^^^^^^^^^^^^^^^
3835

3936

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,33 @@ let Some(x) = Some(42)
1010
//│ ╙── ^^^^^^^^^^^^^^^^^^
1111

1212

13+
object None
14+
15+
let N = None
16+
//│ N = None
17+
18+
:todo
19+
let (None) = N
20+
//│ ╔══[ERROR] Unsupported let binding shape
21+
//│ ║ l.19: let (None) = N
22+
//│ ╙── ^^^^^^^^^^
23+
24+
1325
class Foo(a)
1426

1527
:todo
1628
let Foo(x) = Foo(1) in log(x)
1729
//│ ╔══[ERROR] Unsupported let binding shape
18-
//│ ║ l.16: let Foo(x) = Foo(1) in log(x)
30+
//│ ║ l.28: let Foo(x) = Foo(1) in log(x)
1931
//│ ╙── ^^^^^^^^^^^^^^^
2032
//│ ╔══[ERROR] Name not found: x
21-
//│ ║ l.16: let Foo(x) = Foo(1) in log(x)
33+
//│ ║ l.28: let Foo(x) = Foo(1) in log(x)
2234
//│ ╙── ^
2335

2436
:todo
2537
let Foo(x) and x > 0 = Foo(1) in log("ok")
2638
//│ ╔══[ERROR] Unsupported let binding shape
27-
//│ ║ l.25: let Foo(x) and x > 0 = Foo(1) in log("ok")
39+
//│ ║ l.37: let Foo(x) and x > 0 = Foo(1) in log("ok")
2840
//│ ╙── ^^^^^^^^^^^^^^^^^^^^^^^^^
2941

3042

0 commit comments

Comments
 (0)