@@ -194,11 +194,17 @@ class Lowering()(using Config, TL, Raise, State, Ctx):
194
194
final def term (t : st, inStmtPos : Bool = false )(k : Result => Block )(using Subst ): Block =
195
195
tl.log(s " Lowering.term ${t.showDbg.truncate(100 , " [...]" )}${
196
196
if inStmtPos then " (in stmt)" else " " }${
197
- t.symbol.fold(" " )(" – symbol " + _)}" )
197
+ t.resolvedSymbol.fold(" " )(" – symbol " + _)}" )
198
+
198
199
def warnStmt = if inStmtPos then
199
200
raise :
200
201
WarningReport (msg " Pure expression in statement position " -> t.toLoc :: Nil , S (t))
202
+
203
+ // Funny Scala: the non-exhaustive match is actually the second match
201
204
t match
205
+ case t : sem.Resolvable => t.instantiate
206
+ case t => t
207
+ match
202
208
case st.UnitVal () => k(unit)
203
209
case st.Lit (lit) =>
204
210
warnStmt
@@ -224,37 +230,39 @@ class Lowering()(using Config, TL, Raise, State, Ctx):
224
230
if sym.binary then
225
231
val t1 = new Tree .Ident (" arg1" )
226
232
val t2 = new Tree .Ident (" arg2" )
227
- val p1 = Param (FldFlags .empty, VarSymbol (t1), N )
228
- val p2 = Param (FldFlags .empty, VarSymbol (t2), N )
233
+ val p1 = Param (FldFlags .empty, VarSymbol (t1), N , Modulefulness .none )
234
+ val p2 = Param (FldFlags .empty, VarSymbol (t2), N , Modulefulness .none )
229
235
val ps = PlainParamList (p1 :: p2 :: Nil )
230
- val bod = st.App (t, st.Tup (List (st.Ref (p1.sym)(t1, 666 ) , st.Ref (p2.sym)(t2, 666 ) ))
236
+ val bod = st.App (t, st.Tup (List (st.Ref (p1.sym)(t1, 666 , N ).noIArgs , st.Ref (p2.sym)(t2, 666 , N ).noIArgs ))
231
237
(Tree .Tup (Nil // FIXME should not be required (using dummy value)
232
238
)))(
233
239
Tree .App (Tree .Empty (), Tree .Empty ()), // FIXME should not be required (using dummy value)
240
+ N ,
234
241
FlowSymbol (sym.nme)
235
- )
242
+ ).noIArgs
236
243
val (paramLists, bodyBlock) = setupFunctionDef(ps :: Nil , bod, S (sym.nme))
237
244
tl.log(s " Ref builtin $sym" )
238
245
assert(paramLists.length === 1 )
239
246
return k(Value .Lam (paramLists.head, bodyBlock))
240
247
if sym.unary then
241
248
val t1 = new Tree .Ident (" arg" )
242
- val p1 = Param (FldFlags .empty, VarSymbol (t1), N )
249
+ val p1 = Param (FldFlags .empty, VarSymbol (t1), N , Modulefulness .none )
243
250
val ps = PlainParamList (p1 :: Nil )
244
- val bod = st.App (t, st.Tup (List (st.Ref (p1.sym)(t1, 666 ) ))
251
+ val bod = st.App (t, st.Tup (List (st.Ref (p1.sym)(t1, 666 , N ).noIArgs ))
245
252
(Tree .Tup (Nil // FIXME should not be required (using dummy value)
246
253
)))(
247
254
Tree .App (Tree .Empty (), Tree .Empty ()), // FIXME should not be required (using dummy value)
255
+ N ,
248
256
FlowSymbol (sym.nme)
249
- )
257
+ ).noIArgs
250
258
val (paramLists, bodyBlock) = setupFunctionDef(ps :: Nil , bod, S (sym.nme))
251
259
tl.log(s " Ref builtin $sym" )
252
260
assert(paramLists.length === 1 )
253
261
return k(Value .Lam (paramLists.head, bodyBlock))
254
262
case bs : BlockMemberSymbol =>
255
263
bs.defn match
256
264
case S (d) if d.isDeclare.isDefined =>
257
- return term(Sel (State .globalThisSymbol.ref(), ref.tree)(S (bs)))(k)
265
+ return term(Sel (State .globalThisSymbol.ref().noIArgs , ref.tree)(S (bs)).noIArgs )(k)
258
266
case S (td : TermDefinition ) if td.k is syntax.Fun =>
259
267
// * Local functions with no parameter lists are getters
260
268
// * and are lowered to functions with an empty parameter list
@@ -298,7 +306,7 @@ class Lowering()(using Config, TL, Raise, State, Ctx):
298
306
End (" error" )
299
307
case st.TyApp (f, ts) => term(f)(k) // * Type arguments are erased
300
308
case st.App (f, arg) =>
301
- val isMlsFun = f.symbol .fold(f.isInstanceOf [st.Lam ]):
309
+ val isMlsFun = f.resolvedSymbol .fold(f.isInstanceOf [st.Lam ]):
302
310
case _ : sem.BuiltinSymbol => true
303
311
case sym : sem.BlockMemberSymbol =>
304
312
sym.trmImplTree.fold(sym.clsTree.isDefined)(_.k is syntax.Fun )
@@ -312,17 +320,17 @@ class Lowering()(using Config, TL, Raise, State, Ctx):
312
320
subTerm_nonTail(arg): ar =>
313
321
k(Call (fr, Arg (spread = true , ar) :: Nil )(isMlsFun, true ).withLocOf(t))
314
322
f match
315
- case t if t.symbol .isDefined && (t.symbol .get is ctx.builtins.js.try_catch) =>
323
+ case t if t.resolvedSymbol .isDefined && (t.resolvedSymbol .get is ctx.builtins.js.try_catch) =>
316
324
conclude(Value .Ref (State .runtimeSymbol).selN(Tree .Ident (" try_catch" )))
317
- case t if t.symbol .isDefined && (t.symbol .get is ctx.builtins.debug.printStack) =>
325
+ case t if t.resolvedSymbol .isDefined && (t.resolvedSymbol .get is ctx.builtins.debug.printStack) =>
318
326
if ! config.effectHandlers.exists(_.debug) then
319
327
raise(ErrorReport (
320
328
msg " Debugging functions are not enabled " ->
321
329
t.toLoc :: Nil ,
322
330
source = Diagnostic .Source .Compilation ))
323
331
return End (" error" )
324
332
conclude(Value .Ref (State .runtimeSymbol).selSN(" raisePrintStackEffect" ).withLocOf(f))
325
- case t if t.symbol .isDefined && (t.symbol .get is ctx.builtins.debug.getLocals) =>
333
+ case t if t.resolvedSymbol .isDefined && (t.resolvedSymbol .get is ctx.builtins.debug.getLocals) =>
326
334
if ! config.effectHandlers.exists(_.debug) then
327
335
raise(ErrorReport (
328
336
msg " Debugging functions are not enabled " ->
@@ -532,7 +540,7 @@ class Lowering()(using Config, TL, Raise, State, Ctx):
532
540
Return (Call (Value .Ref (State .builtinOpsMap(" super" )), args)(true , true ), implct = true )
533
541
val clsDef = ClsLikeDefn (N , isym, sym, syntax.Cls , N , Nil , S (clsp),
534
542
mtds, privateFlds, publicFlds, pctor, ctor)
535
- Define (clsDef, term_nonTail(New (sym.ref(), Nil , N ))(k))
543
+ Define (clsDef, term_nonTail(New (sym.ref().noIArgs , Nil , N ))(k))
536
544
537
545
case Try (sub, finallyDo) =>
538
546
val l = new TempSymbol (S (sub))
@@ -605,13 +613,6 @@ class Lowering()(using Config, TL, Raise, State, Ctx):
605
613
case sem.Fld (sem.FldFlags .benign(), idx, S (rhs)) => L (idx -> rhs)
606
614
case arg @ sem.Fld (flags, value, asc) => TODO (s " Other argument forms: $arg" )
607
615
case spd : Spd => R (true -> spd.term)
608
- case ca : sem.CtxArg => ca.term match
609
- case S (t) =>
610
- R (false -> t)
611
- case N =>
612
- // * All contextual arguments should have been
613
- // * populated by implicit resolution before lowering.
614
- lastWords(s " Found unpopulated contextual argument: ${ca}. " )
615
616
// * The straightforward way to lower arguments creates too much recursion depth
616
617
// * and makes Lowering stack overflow when lowering functions with lots of arguments.
617
618
/*
0 commit comments