Skip to content

Commit e45f8b3

Browse files
committed
More changes to dotc so that it can be capture checked
1 parent 9c0a65c commit e45f8b3

22 files changed

+90
-64
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@annotation.experimental class C(x: () => Unit) extends caps.Pure // error
2+
3+
@annotation.experimental class D(@annotation.constructorOnly x: () => Unit) extends caps.Pure // ok
4+

tests/pos-with-compiler-cc/dotc/ast/tpd.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import typer.ConstFold
1818

1919
import scala.annotation.tailrec
2020
import scala.collection.mutable.ListBuffer
21+
import language.experimental.pureFunctions
2122

2223
/** Some creators for typed trees */
2324
object tpd extends Trees.Instance[Type] with TypedTreeInfo {
@@ -1454,7 +1455,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
14541455
* @return The symbols imported.
14551456
*/
14561457
def importedSymbols(imp: Import,
1457-
selectorPredicate: untpd.ImportSelector => Boolean = util.common.alwaysTrue)
1458+
selectorPredicate: untpd.ImportSelector -> Boolean = util.common.alwaysTrue)
14581459
(using Context): List[Symbol] =
14591460
imp.selectors.find(selectorPredicate) match
14601461
case Some(sel) => importedSymbols(imp.expr, sel.name)

tests/pos-with-compiler-cc/dotc/core/classfile/ClassfileParser.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import scala.annotation.switch
2323
import typer.Checking.checkNonCyclic
2424
import io.{AbstractFile, ZipArchive}
2525
import scala.util.control.NonFatal
26+
import language.experimental.pureFunctions
2627

2728
object ClassfileParser {
2829
/** Marker trait for unpicklers that can be embedded in classfiles. */
@@ -629,10 +630,10 @@ class ClassfileParser(
629630
case (name, tag: EnumTag) => untpd.NamedArg(name.name, tag.toTree).withSpan(NoSpan)
630631
}
631632

632-
protected var mySym: Symbol | (Context ?=> Symbol) =
633+
protected var mySym: Symbol | (Context ?-> Symbol) =
633634
(ctx: Context) ?=> annotType.classSymbol
634635

635-
protected var myTree: Tree | (Context ?=> Tree) =
636+
protected var myTree: Tree | (Context ?-> Tree) =
636637
(ctx: Context) ?=> untpd.resolveConstructor(annotType, args)
637638

638639
def untpdTree(using Context): untpd.Tree =

tests/pos-with-compiler-cc/dotc/core/tasty/TastyUnpickler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import TastyBuffer.NameRef
1111
import scala.collection.mutable
1212
import Names.{TermName, termName, EmptyTermName}
1313
import NameKinds._
14+
import language.experimental.pureFunctions
1415

1516
object TastyUnpickler {
1617

1718
abstract class SectionUnpickler[R](val name: String) {
1819
def unpickle(reader: TastyReader, nameAtRef: NameTable): R
1920
}
2021

21-
class NameTable extends (NameRef => TermName) {
22+
class NameTable extends (NameRef -> TermName) {
2223
private val names = new mutable.ArrayBuffer[TermName]
2324
def add(name: TermName): mutable.ArrayBuffer[TermName] = names += name
2425
def apply(ref: NameRef): TermName = names(ref.index)

tests/pos-with-compiler-cc/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import dotty.tools.tasty.TastyFormat._
4646

4747
import scala.annotation.constructorOnly
4848
import scala.annotation.internal.sharable
49+
import language.experimental.pureFunctions
4950

5051
/** Unpickler for typed trees
5152
* @param reader the reader from which to unpickle
@@ -663,9 +664,9 @@ class TreeUnpickler(reader: TastyReader,
663664
/** Read modifier list into triplet of flags, annotations and a privateWithin
664665
* boundary symbol.
665666
*/
666-
def readModifiers(end: Addr)(using Context): (FlagSet, List[Symbol => Annotation], Symbol) = {
667+
def readModifiers(end: Addr)(using Context): (FlagSet, List[Symbol -> Annotation], Symbol) = {
667668
var flags: FlagSet = EmptyFlags
668-
var annotFns: List[Symbol => Annotation] = Nil
669+
var annotFns: List[Symbol -> Annotation] = Nil
669670
var privateWithin: Symbol = NoSymbol
670671
while (currentAddr.index != end.index) {
671672
def addFlag(flag: FlagSet) = {
@@ -732,7 +733,7 @@ class TreeUnpickler(reader: TastyReader,
732733

733734
private def readWithin(using Context): Symbol = readType().typeSymbol
734735

735-
private def readAnnot(using Context): Symbol => Annotation =
736+
private def readAnnot(using Context): Symbol -> Annotation =
736737
readByte()
737738
val end = readEnd()
738739
val tp = readType()
@@ -1450,10 +1451,10 @@ class TreeUnpickler(reader: TastyReader,
14501451
setSpan(start, CaseDef(pat, guard, rhs))
14511452
}
14521453

1453-
def readLater[T <: AnyRef](end: Addr, op: TreeReader => Context ?=> T)(using Context): Trees.Lazy[T] =
1454+
def readLater[T <: AnyRef](end: Addr, op: TreeReader -> Context ?-> T)(using Context): Trees.Lazy[T] =
14541455
readLaterWithOwner(end, op)(ctx.owner)
14551456

1456-
def readLaterWithOwner[T <: AnyRef](end: Addr, op: TreeReader => Context ?=> T)(using Context): Symbol => Trees.Lazy[T] = {
1457+
def readLaterWithOwner[T <: AnyRef](end: Addr, op: TreeReader -> Context ?-> T)(using Context): Symbol -> Trees.Lazy[T] = {
14571458
val localReader = fork
14581459
goto(end)
14591460
val mode = ctx.mode

tests/pos-with-compiler-cc/dotc/parsing/Parsers.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import config.Feature
3333
import config.Feature.{sourceVersion, migrateTo3, globalOnlyImports}
3434
import config.SourceVersion._
3535
import config.SourceVersion
36+
import language.experimental.pureFunctions
3637

3738
object Parsers {
3839

@@ -143,10 +144,10 @@ object Parsers {
143144
syntaxError(msg, Span(offset, offset + length))
144145
lastErrorOffset = in.offset
145146

146-
def syntaxError(msg: => String, offset: Int): Unit =
147+
def syntaxError(msg: -> String, offset: Int): Unit =
147148
syntaxError(msg.toMessage, offset)
148149

149-
def syntaxError(msg: => String): Unit =
150+
def syntaxError(msg: -> String): Unit =
150151
syntaxError(msg, in.offset)
151152

152153
/** Unconditionally issue an error at given span, without
@@ -155,7 +156,7 @@ object Parsers {
155156
def syntaxError(msg: Message, span: Span): Unit =
156157
report.error(msg, source.atSpan(span))
157158

158-
def syntaxError(msg: => String, span: Span): Unit =
159+
def syntaxError(msg: -> String, span: Span): Unit =
159160
syntaxError(msg.toMessage, span)
160161

161162
def unimplementedExpr(using Context): Select =
@@ -288,7 +289,7 @@ object Parsers {
288289
syntaxError(msg, offset)
289290
skip()
290291

291-
def syntaxErrorOrIncomplete(msg: => String): Unit =
292+
def syntaxErrorOrIncomplete(msg: -> String): Unit =
292293
syntaxErrorOrIncomplete(msg.toMessage, in.offset)
293294

294295
def syntaxErrorOrIncomplete(msg: Message, span: Span): Unit =

tests/pos-with-compiler-cc/dotc/sbt/ExtractDependencies.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import xsbti.api.DependencyContext
2525
import xsbti.api.DependencyContext._
2626

2727
import scala.collection.{Set, mutable}
28-
28+
import language.experimental.pureFunctions
2929

3030
/** This phase sends information on classes' dependencies to sbt via callbacks.
3131
*
@@ -189,7 +189,7 @@ object ExtractDependencies {
189189
sym.fullName.stripModuleClassSuffix.toString
190190

191191
/** Report an internal error in incremental compilation. */
192-
def internalError(msg: => String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
192+
def internalError(msg: -> String, pos: SrcPos = NoSourcePosition)(using Context): Unit =
193193
report.error(s"Internal error in the incremental compiler while compiling ${ctx.compilationUnit.source}: $msg", pos)
194194
}
195195

tests/pos-with-compiler-cc/dotc/semanticdb/internal/SemanticdbTypeMapper.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package dotty.tools.dotc.semanticdb.internal
2+
import language.experimental.pureFunctions
23

34
abstract class SemanticdbTypeMapper[BaseType, CustomType] {
45
def toCustom(base: BaseType): CustomType
56
def toBase(custom: CustomType): BaseType
67
}
78

89
object SemanticdbTypeMapper {
9-
def apply[BaseType, CustomType](baseToCustom: BaseType => CustomType)(
10-
customToBase: CustomType => BaseType
10+
def apply[BaseType, CustomType](baseToCustom: BaseType -> CustomType)(
11+
customToBase: CustomType -> BaseType
1112
): SemanticdbTypeMapper[BaseType, CustomType] =
1213
new SemanticdbTypeMapper[BaseType, CustomType] {
1314
def toCustom(base: BaseType): CustomType = baseToCustom(base)

tests/pos-with-compiler-cc/dotc/transform/TypeTestsCasts.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import core.Flags._
1515
import util.Spans._
1616
import reporting._
1717
import config.Printers.{ transforms => debug }
18+
import language.experimental.pureFunctions
1819

1920
/** This transform normalizes type tests and type casts,
2021
* also replacing type tests with singleton argument type with reference equality check
@@ -195,7 +196,7 @@ object TypeTestsCasts {
195196
def testCls = effectiveClass(testType.widen)
196197
def unboxedTestCls = effectiveClass(unboxedTestType.widen)
197198

198-
def unreachable(why: => String)(using Context): Boolean = {
199+
def unreachable(why: -> String)(using Context): Boolean = {
199200
if (flagUnrelated)
200201
if (inMatch) report.error(em"this case is unreachable since $why", expr.srcPos)
201202
else report.warning(em"this will always yield false since $why", expr.srcPos)

tests/pos-with-compiler-cc/dotc/transform/init/Semantic.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Errors.*
1818

1919
import scala.collection.mutable
2020
import scala.annotation.tailrec
21+
import caps.unsafeBoxFunArg
2122

2223
object Semantic:
2324

@@ -1669,7 +1670,8 @@ object Semantic:
16691670
}
16701671

16711672
// initialize super classes after outers are set
1672-
tasks.foreach(task => task())
1673+
tasks.foreach(((task: () => Unit) => task()).unsafeBoxFunArg)
1674+
// !cc! .asInstanceOf needed to convert from `(() => Unit) -> Unit` to `(box () => Unit) -> Unit`.
16731675
end if
16741676

16751677
var fieldsChanged = true

0 commit comments

Comments
 (0)