Skip to content

Commit cea8a6f

Browse files
Merge pull request #10786 from dotty-staging/fix-#10697
Disable old context function syntax
2 parents 18c84fc + d7cfa97 commit cea8a6f

File tree

15 files changed

+42
-35
lines changed

15 files changed

+42
-35
lines changed

compiler/src/dotty/tools/dotc/core/Annotations.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ object Annotations {
124124
object LazyBodyAnnotation {
125125
def apply(bodyFn: Context ?=> Tree): LazyBodyAnnotation =
126126
new LazyBodyAnnotation:
127-
protected var myTree: Tree | (Context ?=> Tree) = (using ctx) => bodyFn(using ctx)
127+
protected var myTree: Tree | (Context ?=> Tree) = ctx ?=> bodyFn(using ctx)
128128
}
129129

130130
object Annotation {
@@ -155,15 +155,15 @@ object Annotations {
155155
/** Create an annotation where the tree is computed lazily. */
156156
def deferred(sym: Symbol)(treeFn: Context ?=> Tree)(using Context): Annotation =
157157
new LazyAnnotation {
158-
protected var myTree: Tree | (Context ?=> Tree) = (using ctx) => treeFn(using ctx)
158+
protected var myTree: Tree | (Context ?=> Tree) = ctx ?=> treeFn(using ctx)
159159
protected var mySym: Symbol | (Context ?=> Symbol) = sym
160160
}
161161

162162
/** Create an annotation where the symbol and the tree are computed lazily. */
163163
def deferredSymAndTree(symFn: Context ?=> Symbol)(treeFn: Context ?=> Tree)(using Context): Annotation =
164164
new LazyAnnotation {
165-
protected var mySym: Symbol | (Context ?=> Symbol) = (using ctx) => symFn(using ctx)
166-
protected var myTree: Tree | (Context ?=> Tree) = (using ctx) => treeFn(using ctx)
165+
protected var mySym: Symbol | (Context ?=> Symbol) = ctx ?=> symFn(using ctx)
166+
protected var myTree: Tree | (Context ?=> Tree) = ctx ?=> treeFn(using ctx)
167167
}
168168

169169
/** Extractor for child annotations */

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2504,7 +2504,7 @@ object SymDenotations {
25042504
}
25052505

25062506
object LazyType:
2507-
private val NoSymbolFn = (using _: Context) => NoSymbol
2507+
private val NoSymbolFn = (_: Context) ?=> NoSymbol
25082508

25092509
/** A subtrait of LazyTypes where completerTypeParams yields a List[TypeSymbol], which
25102510
* should be completed independently of the info.

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5162,7 +5162,7 @@ object Types {
51625162
derivedSuperType(tp, this(thistp), this(supertp))
51635163

51645164
case tp: LazyRef =>
5165-
LazyRef { (using refCtx) =>
5165+
LazyRef { refCtx ?=>
51665166
val ref1 = tp.ref
51675167
if refCtx.runId == mapCtx.runId then this(ref1)
51685168
else // splice in new run into map context

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,10 @@ class ClassfileParser(
585585
}
586586

587587
protected var mySym: Symbol | (Context ?=> Symbol) =
588-
(using ctx: Context) => annotType.classSymbol
588+
(ctx: Context) ?=> annotType.classSymbol
589589

590590
protected var myTree: Tree | (Context ?=> Tree) =
591-
(using ctx: Context) => untpd.resolveConstructor(annotType, args)
591+
(ctx: Context) ?=> untpd.resolveConstructor(annotType, args)
592592

593593
def untpdTree(using Context): untpd.Tree =
594594
untpd.New(untpd.TypeTree(annotType), List(args))

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ class TreeUnpickler(reader: TastyReader,
603603
forkAt(templateStart).indexTemplateParams()(using localContext(sym))
604604
}
605605
else if (sym.isInlineMethod)
606-
sym.addAnnotation(LazyBodyAnnotation { (using ctx0: Context) =>
606+
sym.addAnnotation(LazyBodyAnnotation { (ctx0: Context) ?=>
607607
val ctx1 = localContext(sym)(using ctx0).addMode(Mode.ReadPositions)
608608
inContext(sourceChangeContext(Addr(0))(using ctx1)) {
609609
// avoids space leaks by not capturing the current context

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,7 @@ object Parsers {
13641364
val start = in.offset
13651365
var imods = Modifiers()
13661366
def functionRest(params: List[Tree]): Tree =
1367+
val paramSpan = Span(start, in.lastOffset)
13671368
atSpan(start, in.offset) {
13681369
if in.token == TLARROW then
13691370
if !imods.flags.isEmpty || params.isEmpty then
@@ -1382,14 +1383,16 @@ object Parsers {
13821383
accept(ARROW)
13831384
val t = typ()
13841385

1385-
if (imods.isOneOf(Given | Erased)) new FunctionWithMods(params, t, imods)
1386-
else if (ctx.settings.YkindProjector.value) {
1386+
if imods.isOneOf(Given | Erased) then
1387+
if imods.is(Given) && params.isEmpty then
1388+
syntaxError("context function types require at least one parameter", paramSpan)
1389+
new FunctionWithMods(params, t, imods)
1390+
else if ctx.settings.YkindProjector.value then
13871391
val (newParams :+ newT, tparams) = replaceKindProjectorPlaceholders(params :+ t)
13881392

13891393
lambdaAbstract(tparams, Function(newParams, newT))
1390-
} else {
1394+
else
13911395
Function(params, t)
1392-
}
13931396
}
13941397
def funArgTypesRest(first: Tree, following: () => Tree) = {
13951398
val buf = new ListBuffer[Tree] += first
@@ -1904,10 +1907,7 @@ object Parsers {
19041907

19051908
def expr(location: Location): Tree = {
19061909
val start = in.offset
1907-
def isSpecialClosureStart =
1908-
val lookahead = in.LookaheadScanner()
1909-
lookahead.nextToken()
1910-
lookahead.isIdent(nme.using) || lookahead.token == ERASED
1910+
def isSpecialClosureStart = in.lookahead.token == ERASED
19111911
if in.token == IMPLICIT then
19121912
closure(start, location, modifiers(BitSet(IMPLICIT)))
19131913
else if in.token == LPAREN && isSpecialClosureStart then
@@ -2137,9 +2137,7 @@ object Parsers {
21372137
else
21382138
openParens.change(LPAREN, 1)
21392139
var mods1 = mods
2140-
if mods.flags.isEmpty then
2141-
if isIdent(nme.using) then mods1 = addMod(mods1, atSpan(in.skipToken()) { Mod.Given() })
2142-
if in.token == ERASED then mods1 = addModifier(mods1)
2140+
if in.token == ERASED then mods1 = addModifier(mods1)
21432141
try
21442142
commaSeparated(() => binding(mods1))
21452143
finally
@@ -2188,7 +2186,12 @@ object Parsers {
21882186

21892187
def closureRest(start: Int, location: Location, params: List[Tree]): Tree =
21902188
atSpan(start, in.offset) {
2191-
if in.token == CTXARROW then in.nextToken() else accept(ARROW)
2189+
if in.token == CTXARROW then
2190+
if params.isEmpty then
2191+
syntaxError("context function literals require at least one formal parameter", Span(start, in.lastOffset))
2192+
in.nextToken()
2193+
else
2194+
accept(ARROW)
21922195
Function(params, if (location == Location.InBlock) block() else expr())
21932196
}
21942197

compiler/src/dotty/tools/dotc/quoted/PickledQuotes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ object PickledQuotes {
7474
override def transform(tree: tpd.Tree)(using Context): tpd.Tree = tree match {
7575
case Hole(isTerm, idx, args) =>
7676
val reifiedArgs = args.map { arg =>
77-
if (arg.isTerm) (using q: Quotes) => new ExprImpl(arg, QuotesImpl.scopeId)
77+
if (arg.isTerm) (q: Quotes) ?=> new ExprImpl(arg, QuotesImpl.scopeId)
7878
else new TypeImpl(arg, QuotesImpl.scopeId)
7979
}
8080
if isTerm then

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ object Implicits:
249249
else
250250
val candidates = new mutable.ListBuffer[Candidate]
251251
def tryCandidate(extensionOnly: Boolean)(ref: ImplicitRef) =
252-
var ckind = exploreInFreshCtx { (using ctx: FreshContext) =>
252+
var ckind = exploreInFreshCtx { (ctx: FreshContext) ?=>
253253
ctx.setMode(ctx.mode | Mode.TypevarsMissContext)
254254
candidateKind(ref.underlyingRef)
255255
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
val test =
2+
(using x: Int) => x // error // error
3+
4+
val f = () ?=> 23 // error
5+
val g: ContextFunction0[Int] = ??? // ok
6+
val h: () ?=> Int = ??? // error
7+
8+
object Example3 extends App {
9+
final case class Foo[A, B](run: () ?=> Int) // error
10+
}

tests/pos-macros/i8302.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import scala.quoted._
22
def foo[T](using Quotes, Type[T]): Expr[Any] =
3-
'{ (using q: Quotes) =>
3+
'{ (q: Quotes) ?=>
44
type TT = T
55
val t = Type.of[TT]
66
???
77
}
8-

tests/pos-macros/splice-with-explicit-context.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import scala.quoted._
22

33
def f(a: Expr[Int])(using q: Quotes): Unit =
44

5-
'{ val x: Int = ${ (using q2) => a } }
5+
'{ val x: Int = ${ (q2) ?=> a } }
66

7-
'{ val x: Int = ${ (using q2: q.Nested) => a } }
7+
'{ val x: Int = ${ (q2: q.Nested) ?=> a } }

tests/pos/i7778.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,3 @@ object Example extends App {
55
object Example2 extends App {
66
final case class Foo[A, B](run: (A, B) ?=> Int)
77
}
8-
9-
10-
object Example3 extends App {
11-
final case class Foo[A, B](run: () ?=> Int)
12-
}

tests/run-staging/multi-staging.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Test {
1313
println(run(s1))
1414
}
1515
def stage1(x: Expr[Int])(using Quotes): Expr[Quotes ?=> Expr[Int]] =
16-
val code = '{ (using q1: Quotes) =>
16+
val code = '{ (q1: Quotes) ?=>
1717
val x1 = $x
1818
'{ 1 + ${Expr(x1)} }
1919
}

tests/run-staging/quote-nested-4.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Test {
55
given Toolbox = Toolbox.make(getClass.getClassLoader)
66
def main(args: Array[String]): Unit = withQuotes {
77

8-
val q = '{ (using q: Quotes) =>
8+
val q = '{ (q: Quotes) ?=>
99
val t = Type.of[String]
1010
t
1111
}

tests/run/i10016.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ def f(init: Int ?=> Int) : Int = 1
22
def f(s: String)(init: Int ?=> Int) : Int = 2
33

44
@main def Test() =
5-
assert(f((using x:Int) => x) == 1)
5+
assert(f((x: Int) ?=> x) == 1)

0 commit comments

Comments
 (0)