Skip to content

Commit bdadfd3

Browse files
authored
Move CrossVersionChecks before FirstTransform (#17301)
Fixes #17292
2 parents 824295e + 57c4479 commit bdadfd3

File tree

12 files changed

+57
-44
lines changed

12 files changed

+57
-44
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class Compiler {
5959
/** Phases dealing with the transformation from pickled trees to backend trees */
6060
protected def transformPhases: List[List[Phase]] =
6161
List(new InstrumentCoverage) :: // Perform instrumentation for code coverage (if -coverage-out is set)
62-
List(new FirstTransform, // Some transformations to put trees into a canonical form
62+
List(new CrossVersionChecks, // Check issues related to deprecated and experimental
63+
new FirstTransform, // Some transformations to put trees into a canonical form
6364
new CheckReentrant, // Internal use only: Check that compiled program has no data races involving global vars
6465
new ElimPackagePrefixes, // Eliminate references to package prefixes in Select nodes
6566
new CookComments, // Cook the comments: expand variables, doc, etc.
@@ -71,8 +72,7 @@ class Compiler {
7172
new ElimRepeated, // Rewrite vararg parameters and arguments
7273
new RefChecks) :: // Various checks mostly related to abstract members and overriding
7374
List(new init.Checker) :: // Check initialization of objects
74-
List(new CrossVersionChecks, // Check issues related to deprecated and experimental
75-
new ProtectedAccessors, // Add accessors for protected members
75+
List(new ProtectedAccessors, // Add accessors for protected members
7676
new ExtensionMethods, // Expand methods of value classes with extension methods
7777
new UncacheGivenAliases, // Avoid caching RHS of simple parameterless given aliases
7878
new ElimByName, // Map by-name parameters to functions

compiler/src/dotty/tools/dotc/config/PathResolver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class PathResolver(using c: Context) {
211211
import classPathFactory._
212212

213213
// Assemble the elements!
214-
def basis: List[Traversable[ClassPath]] =
214+
def basis: List[Iterable[ClassPath]] =
215215
val release = Option(ctx.settings.javaOutputVersion.value).filter(_.nonEmpty)
216216

217217
List(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ object SymDenotations {
299299
}
300300

301301
/** Add all given annotations to this symbol */
302-
final def addAnnotations(annots: TraversableOnce[Annotation])(using Context): Unit =
302+
final def addAnnotations(annots: IterableOnce[Annotation])(using Context): Unit =
303303
annots.iterator.foreach(addAnnotation)
304304

305305
@tailrec

compiler/src/dotty/tools/dotc/parsing/xml/MarkupParserCommon.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ package xml
1111

1212
import Utility._
1313
import util.Chars.SU
14-
15-
14+
import scala.collection.BufferedIterator
1615

1716
/** This is not a public trait - it contains common code shared
1817
* between the library level XML parser and the compiler's.

compiler/src/dotty/tools/dotc/parsing/xml/MarkupParsers.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package xml
66
import scala.language.unsafeNulls
77

88
import scala.collection.mutable
9+
import scala.collection.BufferedIterator
910
import core.Contexts.Context
1011
import mutable.{ Buffer, ArrayBuffer, ListBuffer }
1112
import scala.util.control.ControlThrowable

compiler/src/dotty/tools/dotc/printing/Printer.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ abstract class Printer {
174174
atPrec(GlobalPrec) { elem.toText(this) }
175175

176176
/** Render elements alternating with `sep` string */
177-
def toText(elems: Traversable[Showable], sep: String): Text =
177+
def toText(elems: Iterable[Showable], sep: String): Text =
178178
Text(elems map (_ toText this), sep)
179179

180180
/** Render elements within highest precedence */
181-
def toTextLocal(elems: Traversable[Showable], sep: String): Text =
181+
def toTextLocal(elems: Iterable[Showable], sep: String): Text =
182182
atPrec(DotPrec) { toText(elems, sep) }
183183

184184
/** Render elements within lowest precedence */
185-
def toTextGlobal(elems: Traversable[Showable], sep: String): Text =
185+
def toTextGlobal(elems: Iterable[Showable], sep: String): Text =
186186
atPrec(GlobalPrec) { toText(elems, sep) }
187187

188188
/** A plain printer without any embellishments */

compiler/src/dotty/tools/dotc/printing/Texts.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ object Texts {
173173
/** A concatenation of elements in `xs` and interspersed with
174174
* separator strings `sep`.
175175
*/
176-
def apply(xs: Traversable[Text], sep: String = " "): Text =
176+
def apply(xs: Iterable[Text], sep: String = " "): Text =
177177
if (sep == "\n") lines(xs)
178178
else {
179179
val ys = xs.filterNot(_.isEmpty)
@@ -182,7 +182,7 @@ object Texts {
182182
}
183183

184184
/** The given texts `xs`, each on a separate line */
185-
def lines(xs: Traversable[Text]): Vertical = Vertical(xs.toList.reverse)
185+
def lines(xs: Iterable[Text]): Vertical = Vertical(xs.toList.reverse)
186186

187187
extension (text: => Text)
188188
def provided(cond: Boolean): Text = if (cond) text else Str("")

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

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ class CrossVersionChecks extends MiniPhase:
1818

1919
override def description: String = CrossVersionChecks.description
2020

21-
override def runsAfterGroupsOf: Set[String] = Set(FirstTransform.name)
22-
// We assume all type trees except TypeTree have been eliminated
23-
2421
// Note: if a symbol has both @deprecated and @migration annotations and both
2522
// warnings are enabled, only the first one checked here will be emitted.
2623
// I assume that's a consequence of some code trying to avoid noise by suppressing
@@ -69,18 +66,8 @@ class CrossVersionChecks extends MiniPhase:
6966
val since = annot.argumentConstant(1).map(" since " + _.stringValue).getOrElse("")
7067
report.deprecationWarning(em"${sym.showLocated} is deprecated${since}${msg}", pos)
7168

72-
private def checkExperimentalSignature(sym: Symbol, pos: SrcPos)(using Context): Unit =
73-
class Checker extends TypeTraverser:
74-
def traverse(tp: Type): Unit =
75-
if tp.typeSymbol.isExperimental then
76-
Feature.checkExperimentalDef(tp.typeSymbol, pos)
77-
else
78-
traverseChildren(tp)
79-
if !sym.isInExperimentalScope then
80-
new Checker().traverse(sym.info)
81-
8269
private def checkExperimentalAnnots(sym: Symbol)(using Context): Unit =
83-
if !sym.isInExperimentalScope then
70+
if sym.exists && !sym.isInExperimentalScope then
8471
for annot <- sym.annotations if annot.symbol.isExperimental do
8572
Feature.checkExperimentalDef(annot.symbol, annot.tree)
8673

@@ -119,13 +106,16 @@ class CrossVersionChecks extends MiniPhase:
119106
override def transformValDef(tree: ValDef)(using Context): ValDef =
120107
checkDeprecatedOvers(tree)
121108
checkExperimentalAnnots(tree.symbol)
122-
checkExperimentalSignature(tree.symbol, tree)
123109
tree
124110

125111
override def transformDefDef(tree: DefDef)(using Context): DefDef =
126112
checkDeprecatedOvers(tree)
127113
checkExperimentalAnnots(tree.symbol)
128-
checkExperimentalSignature(tree.symbol, tree)
114+
tree
115+
116+
override def transformTypeDef(tree: TypeDef)(using Context): TypeDef =
117+
// TODO do we need to check checkDeprecatedOvers(tree)?
118+
checkExperimentalAnnots(tree.symbol)
129119
tree
130120

131121
override def transformIdent(tree: Ident)(using Context): Ident = {
@@ -157,19 +147,14 @@ class CrossVersionChecks extends MiniPhase:
157147
tree
158148
}
159149

160-
override def transformTypeDef(tree: TypeDef)(using Context): TypeDef = {
161-
checkExperimentalAnnots(tree.symbol)
150+
override def transformOther(tree: Tree)(using Context): Tree =
151+
tree.foreachSubTree { // Find references in type trees and imports
152+
case tree: Ident => transformIdent(tree)
153+
case tree: Select => transformSelect(tree)
154+
case tree: TypeTree => transformTypeTree(tree)
155+
case _ =>
156+
}
162157
tree
163-
}
164-
165-
override def transformOther(tree: Tree)(using Context): Tree = tree match
166-
case tree: Import =>
167-
tree.foreachSubTree {
168-
case t: RefTree => checkUndesiredProperties(t.symbol, t.srcPos)
169-
case _ =>
170-
}
171-
tree
172-
case _ => tree
173158

174159
end CrossVersionChecks
175160

tests/neg-custom-args/deprecation/14034b.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ type Foo0 = Exp // error
99
type Foo = Option[Exp] // error
1010
type Bar = Option[exp.type] // error
1111
type Baz = Exp | Int // error
12-
type Quux = [X] =>> X match // error
13-
case Exp => Int
12+
type Quux = [X] =>> X match
13+
case Exp => Int // error
1414
type Quuz[A <: Exp] = Int // error

tests/neg-custom-args/no-experimental/14034.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ type Foo0 = Exp // error
77
type Foo = Option[Exp] // error
88
type Bar = Option[exp.type] // error
99
type Baz = Exp | Int // error
10-
type Quux = [X] =>> X match // error
11-
case Exp => Int
10+
type Quux = [X] =>> X match
11+
case Exp => Int // error
1212
type Quuz[A <: Exp] = Int // error
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import annotation.experimental
2+
3+
class Foo { @experimental type Bar = (Int, String) }
4+
5+
val f: Foo = Foo()
6+
7+
def g: Tuple.Elem[f.Bar, 0] = ??? // error
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import annotation.experimental
2+
type A[T] = Int
3+
class Foo {
4+
@experimental type Bar = (Int, String)
5+
}
6+
7+
type Elem1[X <: Tuple, N <: Int] = X match { case x *: xs => N match { case 0 => x } }
8+
type Elem2[X <: Tuple, N <: Int]
9+
10+
val f: Foo = Foo()
11+
12+
def bar1: f.Bar = ??? // error
13+
def bar2 = // error
14+
??? : f.Bar // error
15+
16+
def g0: Elem1[f.Bar, 0] = ??? // error
17+
def g1(a: Elem1[f.Bar, 0]) = ??? // error
18+
def g2 =
19+
??? : Elem1[f.Bar, 0] // error
20+
21+
def h: Elem2[f.Bar, 0] = ??? // error

0 commit comments

Comments
 (0)