Skip to content
Prev Previous commit
Next Next commit
Fixes after rebase
  • Loading branch information
nicolasstucki committed May 5, 2021
commit 540e22f17934f9f5ab94e82ed838c6f7807e5c75
3 changes: 0 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
ctx
super.transform(tree)(using gadtCtx)
case tree: Ident if !tree.isType =>
Experimental.checkExperimental(tree)
if tree.symbol.is(Inline) && !Inliner.inInlineMethod then
ctx.compilationUnit.needsInlining = true
checkNoConstructorProxy(tree)
Expand All @@ -275,7 +274,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
case _ => tree
}
case tree @ Select(qual, name) =>
Experimental.checkExperimental(tree)
if tree.symbol.is(Inline) then
ctx.compilationUnit.needsInlining = true
if (name.isTypeName) {
Expand Down Expand Up @@ -394,7 +392,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
Checking.checkRealizable(ref.tpe, ref.srcPos)
super.transform(tree)
case tree: TypeTree =>
Experimental.checkExperimental(tree)
tree.withType(
tree.tpe match {
case AnnotatedType(tpe, annot) => AnnotatedType(tpe, transformAnnot(annot))
Expand Down
26 changes: 26 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import reporting._
import scala.util.matching.Regex._
import Constants.Constant
import NullOpsDecorator._
import dotty.tools.dotc.config.Feature

object RefChecks {
import tpd._
Expand Down Expand Up @@ -927,6 +928,7 @@ object RefChecks {
// arbitrarily choose one as more important than the other.
private def checkUndesiredProperties(sym: Symbol, pos: SrcPos)(using Context): Unit =
checkDeprecated(sym, pos)
checkExperimental(sym, pos)

val xMigrationValue = ctx.settings.Xmigration.value
if xMigrationValue != NoScalaVersion then
Expand Down Expand Up @@ -967,6 +969,25 @@ object RefChecks {
val since = annot.argumentConstant(1).map(" since " + _.stringValue).getOrElse("")
report.deprecationWarning(s"${sym.showLocated} is deprecated${since}${msg}", pos)

private def checkExperimental(sym: Symbol, pos: SrcPos)(using Context): Unit =
if sym.isExperimental
&& !sym.isConstructor // already reported on the class
&& !ctx.owner.isExperimental // already reported on the @experimental of the owner
&& !sym.is(ModuleClass) // already reported on the module
&& (sym.span.exists || sym != defn.ExperimentalAnnot) // already reported on inferred annotations
then
Feature.checkExperimentalDef(sym, pos)

private def checkExperimentalTypes(tpe: Type, pos: SrcPos)(using Context): Unit =
val checker = new TypeTraverser:
def traverse(tp: Type): Unit =
if tp.typeSymbol.isExperimental then
Feature.checkExperimentalDef(tp.typeSymbol, pos)
else
traverseChildren(tp)
if !pos.span.isSynthetic then // avoid double errors
checker.traverse(tpe)

/** If @migration is present (indicating that the symbol has changed semantics between versions),
* emit a warning.
*/
Expand Down Expand Up @@ -1281,6 +1302,11 @@ class RefChecks extends MiniPhase { thisPhase =>
}
tree
}

override def transformTypeTree(tree: TypeTree)(using Context): TypeTree = {
checkUndesiredProperties(tree.symbol, tree.srcPos)
tree
}
}

/* todo: rewrite and re-enable
Expand Down
19 changes: 0 additions & 19 deletions compiler/src/dotty/tools/dotc/util/Experimental.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,6 @@ import dotty.tools.dotc.transform.SymUtils._
object Experimental:
import tpd._

def checkExperimental(tree: Tree)(using Context): Unit =
if tree.symbol.isExperimental
&& !tree.symbol.isConstructor // already reported on the class
&& !ctx.owner.isExperimental // already reported on the @experimental of the owner
&& !tree.symbol.is(ModuleClass) // already reported on the module
&& (tree.span.exists || tree.symbol != defn.ExperimentalAnnot) // already reported on inferred annotations
then
Feature.checkExperimentalDef(tree.symbol, tree)

def checkExperimentalTypes(tree: Tree)(using Context): Unit =
val checker = new TypeTraverser:
def traverse(tp: Type): Unit =
if tp.typeSymbol.isExperimental then
Feature.checkExperimentalDef(tp.typeSymbol, tree)
else
traverseChildren(tp)
if !tree.span.isSynthetic then // avoid double errors
checker.traverse(tree.tpe)

def annotateExperimental(sym: Symbol)(using Context): Unit =
if sym.is(Enum) && sym.hasAnnotation(defn.ExperimentalAnnot) then
// Add @experimental annotation to enum class definitions
Expand Down
103 changes: 0 additions & 103 deletions tests/neg-custom-args/no-experimental/experimentalAnnotation.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import scala.annotation.experimental

@experimental // error
@experimental // FIXME ERROR
enum E: // error
case A
case B // error
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
class MyExperimentalAnnot extends scala.annotation.experimental // error
class MyExperimentalAnnot // error
extends scala.annotation.experimental // error
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import scala.annotation.experimental

@experimental // error
@experimental // FIXME ERROR
class A:
def f() = 1

@experimental // error
@experimental // FIXME ERROR
class B extends A:
override def f() = 2

class C:
@experimental // error
@experimental // FIXME ERROR
def f() = 1

class D extends C:
override def f() = 2

trait A2:
@experimental // error
@experimental // FIXME ERROR
def f(): Int

trait B2:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import scala.annotation.experimental

@experimental // error
@experimental // FIXME ERROR
trait ExpSAM {
def foo(x: Int): Int
}
Expand Down
8 changes: 4 additions & 4 deletions tests/neg-custom-args/no-experimental/experimentalTerms.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import scala.annotation.experimental

@experimental // error
@experimental // FIXME ERROR
val x = ()

@experimental // error
@experimental // FIXME ERROR
def f() = ()

@experimental // error
@experimental // FIXME ERROR
object X:
def fx() = 1

def test: Unit =
f() // error
x // error
X.fx() // error
import X.fx // error
import X.fx
fx() // error
()
12 changes: 6 additions & 6 deletions tests/neg-custom-args/no-experimental/experimentalType.scala
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import scala.annotation.experimental

@experimental // error
@experimental // FIXME ERROR
class A

@experimental // error
@experimental // FIXME ERROR
class B extends A

@experimental // error
@experimental // FIXME ERROR
type X

@experimental // error
@experimental // FIXME ERROR
type Y = Int

@experimental // error
@experimental // FIXME ERROR
opaque type Z = Int

def test(
p1: A, // error
p2: List[A], // error
p2: List[A], // FIXME ERROR
p3: X, // error
p4: Y, // error
p5: Z, // error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import scala.annotation.experimental

@experimental // error
@experimental // FIXME ERROR
class A

object Extractor1:
def unapply(s: Any): Option[A] = ??? // error
def unapply(s: Any): Option[A] = ??? // FIXME ERROR

object Extractor2:
@experimental // error
@experimental // FIXME ERROR
def unapply(s: Any): Option[Int] = ???

def test: Unit =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import scala.annotation.experimental

@experimental // error
@experimental // FIXME ERROR
inline def g() = ()

def test: Unit =
Expand Down