From 83882eb5856f05c4a986b2623935439d4d04863f Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 11 Jan 2018 18:00:55 +0100 Subject: [PATCH 1/5] Fix #2333: Check if class is deprecated --- compiler/src/dotty/tools/dotc/transform/PostTyper.scala | 7 +++++-- tests/neg-custom-args/i2333.scala | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/neg-custom-args/i2333.scala diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index 46fb723e2391..b5ba15c791c5 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -257,8 +257,11 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase case tree: MemberDef => transformMemberDef(tree) super.transform(tree) - case tree: New if isCheckable(tree) => - Checking.checkInstantiable(tree.tpe, tree.pos) + case tree: New => + if (tree.tpe.classSymbol.hasAnnotation(defn.DeprecatedAnnot)) + ctx.deprecationWarning(s"${tree.tpe.typeSymbol} is deprecated", tree.pos) + if (isCheckable(tree)) + Checking.checkInstantiable(tree.tpe, tree.pos) super.transform(tree) case tree @ Annotated(annotated, annot) => cpy.Annotated(tree)(transform(annotated), transformAnnot(annot)) diff --git a/tests/neg-custom-args/i2333.scala b/tests/neg-custom-args/i2333.scala new file mode 100644 index 000000000000..1dc1e6ec1f4c --- /dev/null +++ b/tests/neg-custom-args/i2333.scala @@ -0,0 +1,5 @@ +@deprecated("bla", "2.11.0") class Foo + +object Test { + new Foo // error +} From 72aa1a45e6fe3eba6142373ec45876c0b9d983f1 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 11 Jan 2018 19:03:31 +0100 Subject: [PATCH 2/5] Add missing test --- compiler/test/dotty/tools/dotc/CompilationTests.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 981582e67efe..82bb6ef523f1 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -186,6 +186,7 @@ class CompilationTests extends ParallelTesting { compileFile("../tests/neg-custom-args/xfatalWarnings.scala", defaultOptions.and("-Xfatal-warnings")) + compileFile("../tests/neg-custom-args/pureStatement.scala", defaultOptions.and("-Xfatal-warnings")) + compileFile("../tests/neg-custom-args/i3589-a.scala", defaultOptions.and("-Xfatal-warnings")) + + compileFile("../tests/neg-custom-args/i2333.scala", defaultOptions.and("-Xfatal-warnings")) + compileFile("../tests/neg-custom-args/phantom-overload.scala", allowDoubleBindings) + compileFile("../tests/neg-custom-args/phantom-overload-2.scala", allowDoubleBindings) + compileFile("../tests/neg-custom-args/structural.scala", defaultOptions.and("-Xfatal-warnings")) From 0326a8fb0daa6637e951c8ec9f17338075fb316c Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 11 Jan 2018 19:04:21 +0100 Subject: [PATCH 3/5] Use checkUndesiredProperties on New --- compiler/src/dotty/tools/dotc/transform/PostTyper.scala | 7 ++----- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 1 + 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index b5ba15c791c5..46fb723e2391 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -257,11 +257,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase case tree: MemberDef => transformMemberDef(tree) super.transform(tree) - case tree: New => - if (tree.tpe.classSymbol.hasAnnotation(defn.DeprecatedAnnot)) - ctx.deprecationWarning(s"${tree.tpe.typeSymbol} is deprecated", tree.pos) - if (isCheckable(tree)) - Checking.checkInstantiable(tree.tpe, tree.pos) + case tree: New if isCheckable(tree) => + Checking.checkInstantiable(tree.tpe, tree.pos) super.transform(tree) case tree @ Annotated(annotated, annot) => cpy.Annotated(tree)(transform(annotated), transformAnnot(annot)) diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index aaadbb66ec12..36ab320d7ef8 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -879,6 +879,7 @@ class RefChecks extends MiniPhase { thisPhase => } override def transformNew(tree: New)(implicit ctx: Context) = { + checkUndesiredProperties(tree.tpe.typeSymbol, tree.pos) currentLevel.enterReference(tree.tpe.typeSymbol, tree.pos) tree } From 73ac2969a6ec715d03d1a20ec5a1beac4f89863d Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 11 Jan 2018 19:33:27 +0100 Subject: [PATCH 4/5] Micro optimisation --- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 36ab320d7ef8..138830b1e2cb 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -879,8 +879,9 @@ class RefChecks extends MiniPhase { thisPhase => } override def transformNew(tree: New)(implicit ctx: Context) = { - checkUndesiredProperties(tree.tpe.typeSymbol, tree.pos) - currentLevel.enterReference(tree.tpe.typeSymbol, tree.pos) + val sym = tree.tpe.typeSymbol + checkUndesiredProperties(sym, tree.pos) + currentLevel.enterReference(sym, tree.pos) tree } } From 6129ac500d30a461ce9369d37e5025275fd06622 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 11 Jan 2018 19:36:26 +0100 Subject: [PATCH 5/5] Add test --- tests/neg-custom-args/i2333.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/neg-custom-args/i2333.scala b/tests/neg-custom-args/i2333.scala index 1dc1e6ec1f4c..a6772e77783e 100644 --- a/tests/neg-custom-args/i2333.scala +++ b/tests/neg-custom-args/i2333.scala @@ -1,5 +1,8 @@ -@deprecated("bla", "2.11.0") class Foo +@deprecated("bla", "2.11.0") class Foo { + def this(x: Int) = this() +} object Test { - new Foo // error -} + new Foo // error: deprecated + new Foo(1) // error: deprecated +} \ No newline at end of file