From 3c6ebeec796b74b816a6348f9c104b2d1eaa32f0 Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Thu, 27 Sep 2018 14:32:26 +0200 Subject: [PATCH] Don't report Dynamic inheritance warning on Dynamic itself --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 8 +++++++- compiler/test/dotty/tools/dotc/CompilationTests.scala | 2 +- tests/pos-special/fatal-warnings/Dynamic.scala | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 tests/pos-special/fatal-warnings/Dynamic.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 8a83f3814582..6f7dde5baa70 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1603,7 +1603,13 @@ class Typer extends Namer } val cdef1 = assignType(cpy.TypeDef(cdef)(name, impl1), cls) checkVariance(cdef1) - if (ctx.phase.isTyper && cdef1.tpe.derivesFrom(defn.DynamicClass) && !ctx.dynamicsEnabled) { + + val reportDynamicInheritance = + ctx.phase.isTyper && + cdef1.symbol.ne(defn.DynamicClass) && + cdef1.tpe.derivesFrom(defn.DynamicClass) && + !ctx.dynamicsEnabled + if (reportDynamicInheritance) { val isRequired = parents1.exists(_.tpe.isRef(defn.DynamicClass)) ctx.featureWarning(nme.dynamics.toString, "extension of type scala.Dynamic", isScala2Feature = true, cls, isRequired, cdef.pos) diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index e76934395b15..246ba6ec1643 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -48,7 +48,7 @@ class CompilationTests extends ParallelTesting { compileFile("tests/pos-special/completeFromSource/Test2.scala", defaultOptions.and("-sourcepath", "tests/pos-special")) + compileFile("tests/pos-special/completeFromSource/Test3.scala", defaultOptions.and("-sourcepath", "tests/pos-special", "-scansource")) + compileFile("tests/pos-special/completeFromSource/nested/Test4.scala", defaultOptions.and("-sourcepath", "tests/pos-special", "-scansource")) + - compileFilesInDir("tests/pos-special/fatal-warnings", defaultOptions.and("-Xfatal-warnings")) + + compileFilesInDir("tests/pos-special/fatal-warnings", defaultOptions.and("-Xfatal-warnings", "-feature")) + compileList( "compileMixed", List( diff --git a/tests/pos-special/fatal-warnings/Dynamic.scala b/tests/pos-special/fatal-warnings/Dynamic.scala new file mode 100644 index 000000000000..3a404ea07e13 --- /dev/null +++ b/tests/pos-special/fatal-warnings/Dynamic.scala @@ -0,0 +1,3 @@ +package scala + +trait Dynamic extends Any