From b43d013c520ac9e18238f3519a0822cf6b06a901 Mon Sep 17 00:00:00 2001 From: extempore Date: Wed, 4 Nov 2009 20:12:41 +0000 Subject: [PATCH] Proposed fix for #2144 plus test case. git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@19399 5e8d7ff9-d8ef-0310-90f0-a4852d11357a --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 9 +++++++-- test/files/neg/bug2144.check | 4 ++++ test/files/neg/bug2144.scala | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/files/neg/bug2144.check create mode 100644 test/files/neg/bug2144.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 5e5831038..cdb38d672 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1700,8 +1700,13 @@ trait Typers { self: Analyzer => computeParamAliases(meth.owner, vparamss1, rhs1) if (tpt1.tpe.typeSymbol != NothingClass && !context.returnsSeen) rhs1 = checkDead(rhs1) - if (meth.owner.isRefinementClass && meth.allOverriddenSymbols.isEmpty) - for (vparams <- ddef.vparamss; vparam <- vparams) + // If only refinement owned methods are checked, invalid code can result; see ticket #2144. + def requiresStructuralCheck = meth.allOverriddenSymbols.isEmpty && ( + meth.owner.isRefinementClass || + (!meth.isConstructor && !meth.isSetter && meth.owner.isAnonymousClass) + ) + if (requiresStructuralCheck) + for (vparam <- ddef.vparamss.flatten) checkStructuralCondition(meth.owner, vparam) if (phase.id <= currentRun.typerPhase.id && meth.owner.isClass && diff --git a/test/files/neg/bug2144.check b/test/files/neg/bug2144.check new file mode 100644 index 000000000..ba3238dcf --- /dev/null +++ b/test/files/neg/bug2144.check @@ -0,0 +1,4 @@ +bug2144.scala:2: error: Parameter type in structural refinement may not refer to abstract type defined outside that same refinement + def foo[A](a: A) = new { def bar(x: A): A = x } + ^ +one error found diff --git a/test/files/neg/bug2144.scala b/test/files/neg/bug2144.scala new file mode 100644 index 000000000..af9a5e166 --- /dev/null +++ b/test/files/neg/bug2144.scala @@ -0,0 +1,3 @@ +object Test { + def foo[A](a: A) = new { def bar(x: A): A = x } +}