@@ -112,13 +112,13 @@ object NoContext extends FreshCtx(-1):
112
112
113
113
type FreshContext = {* } FreshCtx
114
114
115
- def ctx (using c : Context ): {c} Ctx = c
115
+ inline def ctx (using c : Context ): {c} Ctx = c
116
116
117
117
// !cc! it does not work if ctxStack is an Array[FreshContext] instead.
118
118
var ctxStack = Array .tabulate(16 )(new FreshCtx (_))
119
119
var curLevel = 0
120
120
121
- def inFreshContext [ T ]( op : FreshContext ?-> T )( using Context ): T =
121
+ private def freshContext ( using Context ): FreshContext =
122
122
if curLevel == ctxStack.length then
123
123
val prev = ctxStack
124
124
ctxStack = new Array [FreshCtx ](curLevel * 2 )
@@ -127,17 +127,17 @@ def inFreshContext[T](op: FreshContext ?-> T)(using Context): T =
127
127
ctxStack(level) = FreshCtx (level)
128
128
val result = ctxStack(curLevel).initFrom(ctx)
129
129
curLevel += 1
130
- try op(using result)
131
- finally curLevel -= 1
130
+ result
132
131
133
- def withOwner [T ](owner : Symbol )(op : Context ?-> T )(using Context ): T =
134
- val prev = ctx
132
+ inline def inFreshContext [T ](inline op : FreshContext ?-> T )(using Context ): T =
133
+ try op(using freshContext) finally curLevel -= 1
134
+
135
+ inline def withOwner [T ](owner : Symbol )(inline op : Context ?-> T )(using Context ): T =
135
136
inFreshContext : c ?=>
136
137
c.owner = owner
137
138
op
138
139
139
- def withScope [T ](scope : Scope )(op : Context ?-> T )(using Context ): T =
140
- val prev = ctx
140
+ inline def withScope [T ](scope : Scope )(inline op : Context ?-> T )(using Context ): T =
141
141
inFreshContext : c ?=>
142
142
c.scope = scope
143
143
op
@@ -168,8 +168,8 @@ def typedUnadapted(tree: Tree, expected: Type = NoType)(using Context): Type = t
168
168
sym.info = withOwner(sym):
169
169
typed(rhs)
170
170
ctx.scope.enter(sym)
171
- try typed(res, expected)
172
- finally for sym <- ctx.scope.elements do sym.info
171
+ for sym <- ctx.scope.elements do sym.info
172
+ typed(res, expected)
173
173
case Ref (name : String ) =>
174
174
def findIn (c : Context ): Symbol =
175
175
val sym = c.scope.lookup(name)
@@ -188,7 +188,7 @@ def typedUnadapted(tree: Tree, expected: Type = NoType)(using Context): Type = t
188
188
case value : Int => IntType ()
189
189
case value : String => StringType ()
190
190
case _ =>
191
- report.error(s " Int or String literzal expected by $value found " )
191
+ report.error(s " Int or String literal expected by $value found " )
192
192
NoType
193
193
194
194
object sugar :
@@ -203,7 +203,7 @@ import sugar.*
203
203
204
204
val prog =
205
205
Ref (" x" ) + Length (Ref (" s" )) where (
206
- " x" := Lit (1 ),
206
+ " x" := Lit (1 ) + Length ( Ref ( " s " )) ,
207
207
" s" := Lit (" abc" ))
208
208
209
209
val bad = Ref (" x" ) + Ref (" s" ) where (
0 commit comments