@@ -112,13 +112,13 @@ object NoContext extends FreshCtx(-1):
112112
113113type FreshContext = {* } FreshCtx
114114
115- def ctx (using c : Context ): {c} Ctx = c
115+ inline def ctx (using c : Context ): {c} Ctx = c
116116
117117// !cc! it does not work if ctxStack is an Array[FreshContext] instead.
118118var ctxStack = Array .tabulate(16 )(new FreshCtx (_))
119119var curLevel = 0
120120
121- def inFreshContext [ T ]( op : FreshContext ?-> T )( using Context ): T =
121+ private def freshContext ( using Context ): FreshContext =
122122 if curLevel == ctxStack.length then
123123 val prev = ctxStack
124124 ctxStack = new Array [FreshCtx ](curLevel * 2 )
@@ -127,17 +127,17 @@ def inFreshContext[T](op: FreshContext ?-> T)(using Context): T =
127127 ctxStack(level) = FreshCtx (level)
128128 val result = ctxStack(curLevel).initFrom(ctx)
129129 curLevel += 1
130- try op(using result)
131- finally curLevel -= 1
130+ result
132131
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 =
135136 inFreshContext : c ?=>
136137 c.owner = owner
137138 op
138139
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 =
141141 inFreshContext : c ?=>
142142 c.scope = scope
143143 op
@@ -168,8 +168,8 @@ def typedUnadapted(tree: Tree, expected: Type = NoType)(using Context): Type = t
168168 sym.info = withOwner(sym):
169169 typed(rhs)
170170 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)
173173 case Ref (name : String ) =>
174174 def findIn (c : Context ): Symbol =
175175 val sym = c.scope.lookup(name)
@@ -188,7 +188,7 @@ def typedUnadapted(tree: Tree, expected: Type = NoType)(using Context): Type = t
188188 case value : Int => IntType ()
189189 case value : String => StringType ()
190190 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 " )
192192 NoType
193193
194194object sugar :
@@ -203,7 +203,7 @@ import sugar.*
203203
204204val prog =
205205 Ref (" x" ) + Length (Ref (" s" )) where (
206- " x" := Lit (1 ),
206+ " x" := Lit (1 ) + Length ( Ref ( " s " )) ,
207207 " s" := Lit (" abc" ))
208208
209209val bad = Ref (" x" ) + Ref (" s" ) where (
0 commit comments