aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/src/dotty/tools/dotc/core/NameKinds.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/core/TypeOps.scala7
-rw-r--r--compiler/src/dotty/tools/dotc/core/Types.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/transform/patmat/Space.scala5
-rw-r--r--compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala17
-rw-r--r--compiler/test/dotty/tools/dotc/CompilationTests.scala1
-rw-r--r--compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala5
-rw-r--r--tests/neg/customArgs/overloadsOnAbstractTypes.scala22
-rw-r--r--tests/patmat/i2253.scala7
-rw-r--r--tests/patmat/i2254.scala6
-rw-r--r--tests/pos/i2152.scala7
11 files changed, 66 insertions, 15 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/NameKinds.scala b/compiler/src/dotty/tools/dotc/core/NameKinds.scala
index 0f08e4701..81ac3a02f 100644
--- a/compiler/src/dotty/tools/dotc/core/NameKinds.scala
+++ b/compiler/src/dotty/tools/dotc/core/NameKinds.scala
@@ -209,7 +209,7 @@ object NameKinds {
val InlineAccessorName = new UniqueNameKind("$_inlineAccessor_$")
val TempResultName = new UniqueNameKind("ev$")
val EvidenceParamName = new UniqueNameKind("evidence$")
- val DepParamName = new UniqueNameKind("<param>")
+ val DepParamName = new UniqueNameKind("(param)")
val LazyImplicitName = new UniqueNameKind("$_lazy_implicit_$")
val LazyLocalName = new UniqueNameKind("$lzy")
val LazyLocalInitName = new UniqueNameKind("$lzyINIT")
diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala
index 9593bfe93..4a1c3d044 100644
--- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala
+++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala
@@ -7,6 +7,7 @@ import SymDenotations._, Denotations.SingleDenotation
import config.Printers.typr
import util.Positions._
import NameOps._
+import NameKinds.DepParamName
import Decorators._
import StdNames._
import Annotations._
@@ -158,7 +159,11 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
case tp1 => tp1
}
case tp: TypeParamRef =>
- typerState.constraint.typeVarOfParam(tp) orElse tp
+ if (tp.paramName.is(DepParamName)) {
+ val bounds = ctx.typeComparer.bounds(tp)
+ if (bounds.lo.isRef(defn.NothingClass)) bounds.hi else bounds.lo
+ }
+ else typerState.constraint.typeVarOfParam(tp) orElse tp
case _: ThisType | _: BoundType | NoPrefix =>
tp
case tp: RefinedType =>
diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala
index c8c1886cc..955a5a11c 100644
--- a/compiler/src/dotty/tools/dotc/core/Types.scala
+++ b/compiler/src/dotty/tools/dotc/core/Types.scala
@@ -3509,7 +3509,7 @@ object Types {
def apply(tp: Type): Type
- protected var variance = 1
+ protected[core] var variance = 1
protected def derivedSelect(tp: NamedType, pre: Type): Type =
tp.derivedSelect(pre)
diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
index baf1ae356..fe2983896 100644
--- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
+++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
@@ -324,7 +324,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
debug.println(s"candidates for ${tp.show} : [${children.map(_.show).mkString(", ")}]")
- tp match {
+ tp.dealias match {
case OrType(tp1, tp2) => List(Typ(tp1, true), Typ(tp2, true))
case _ if tp =:= ctx.definitions.BooleanType =>
List(
@@ -379,7 +379,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
def canDecompose(tp: Type): Boolean = {
val res = tp.classSymbol.is(allOf(Abstract, Sealed)) ||
tp.classSymbol.is(allOf(Trait, Sealed)) ||
- tp.isInstanceOf[OrType] ||
+ tp.dealias.isInstanceOf[OrType] ||
tp =:= ctx.definitions.BooleanType ||
tp.classSymbol.is(allOf(Enum, Sealed)) // Enum value doesn't have Sealed flag
@@ -537,6 +537,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
tp.refinedName,
tpb.derivedTypeBounds(follow(lo, false), follow(hi, true))
)
+ case tp => tp
}
case _ => tp
}
diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
index 398a7a17e..5d8240362 100644
--- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
+++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
@@ -377,9 +377,10 @@ object ProtoTypes {
* Also, if `owningTree` is non-empty, add a type variable for each parameter.
* @return The added type lambda, and the list of created type variables.
*/
- def constrained(tl: TypeLambda, owningTree: untpd.Tree)(implicit ctx: Context): (TypeLambda, List[TypeTree]) = {
+ def constrained(tl: TypeLambda, owningTree: untpd.Tree, alwaysAddTypeVars: Boolean = false)(implicit ctx: Context): (TypeLambda, List[TypeTree]) = {
val state = ctx.typerState
- assert(!(ctx.typerState.isCommittable && owningTree.isEmpty),
+ val addTypeVars = alwaysAddTypeVars || !owningTree.isEmpty
+ assert(!(ctx.typerState.isCommittable && !addTypeVars),
s"inconsistent: no typevars were added to committable constraint ${state.constraint}")
def newTypeVars(tl: TypeLambda): List[TypeTree] =
@@ -392,7 +393,7 @@ object ProtoTypes {
val added =
if (state.constraint contains tl) tl.newLikeThis(tl.paramNames, tl.paramInfos, tl.resultType)
else tl
- val tvars = if (owningTree.isEmpty) Nil else newTypeVars(added)
+ val tvars = if (addTypeVars) newTypeVars(added) else Nil
ctx.typeComparer.addToConstraint(added, tvars.tpes.asInstanceOf[List[TypeVar]])
(added, tvars)
}
@@ -400,13 +401,13 @@ object ProtoTypes {
/** Same as `constrained(tl, EmptyTree)`, but returns just the created type lambda */
def constrained(tl: TypeLambda)(implicit ctx: Context): TypeLambda = constrained(tl, EmptyTree)._1
- /** Create a new TypeParamRef that represents a dependent method parameter singleton */
- def newDepTypeParamRef(tp: Type)(implicit ctx: Context): TypeParamRef = {
+ /** Create a new TypeVar that represents a dependent method parameter singleton */
+ def newDepTypeVar(tp: Type)(implicit ctx: Context): TypeVar = {
val poly = PolyType(DepParamName.fresh().toTypeName :: Nil)(
pt => TypeBounds.upper(AndType(tp, defn.SingletonType)) :: Nil,
pt => defn.AnyType)
- ctx.typeComparer.addToConstraint(poly, Nil)
- TypeParamRef(poly, 0)
+ constrained(poly, untpd.EmptyTree, alwaysAddTypeVars = true)
+ ._2.head.tpe.asInstanceOf[TypeVar]
}
/** The result type of `mt`, where all references to parameters of `mt` are
@@ -415,7 +416,7 @@ object ProtoTypes {
def resultTypeApprox(mt: MethodType)(implicit ctx: Context): Type =
if (mt.isDependent) {
def replacement(tp: Type) =
- if (ctx.mode.is(Mode.TypevarsMissContext)) WildcardType else newDepTypeParamRef(tp)
+ if (ctx.mode.is(Mode.TypevarsMissContext)) WildcardType else newDepTypeVar(tp)
mt.resultType.substParams(mt, mt.paramInfos.map(replacement))
}
else mt.resultType
diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala
index ff50d7238..cf9b200d4 100644
--- a/compiler/test/dotty/tools/dotc/CompilationTests.scala
+++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala
@@ -156,6 +156,7 @@ class CompilationTests extends ParallelTesting {
compileFile("../tests/neg/customArgs/nopredef.scala", defaultOptions.and("-Yno-predef")) +
compileFile("../tests/neg/customArgs/noimports.scala", defaultOptions.and("-Yno-imports")) +
compileFile("../tests/neg/customArgs/noimports2.scala", defaultOptions.and("-Yno-imports")) +
+ compileFile("../tests/neg/customArgs/overloadsOnAbstractTypes.scala", allowDoubleBindings) +
compileFile("../tests/neg/tailcall/t1672b.scala", defaultOptions) +
compileFile("../tests/neg/tailcall/t3275.scala", defaultOptions) +
compileFile("../tests/neg/tailcall/t6574.scala", defaultOptions) +
diff --git a/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala b/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala
index ad068e9ef..610466224 100644
--- a/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala
+++ b/compiler/test/dotty/tools/vulpix/RunnerOrchestration.scala
@@ -3,6 +3,7 @@ package tools
package vulpix
import java.io.{ File => JFile, InputStreamReader, BufferedReader, PrintStream }
+import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.TimeoutException
import scala.concurrent.duration.Duration
@@ -84,11 +85,11 @@ trait RunnerOrchestration {
}
/** Did add hook to kill the child VMs? */
- private[this] var didAddCleanupCallback = false
+ private[this] val didAddCleanupCallback = new AtomicBoolean(false)
/** Blocks less than `maxDuration` while running `Test.main` from `dir` */
def runMain(classPath: String)(implicit summaryReport: SummaryReporting): Status = {
- if (!didAddCleanupCallback) {
+ if (didAddCleanupCallback.compareAndSet(false, true)) {
// If for some reason the test runner (i.e. sbt) doesn't kill the VM, we
// need to clean up ourselves.
summaryReport.addCleanup(killAll)
diff --git a/tests/neg/customArgs/overloadsOnAbstractTypes.scala b/tests/neg/customArgs/overloadsOnAbstractTypes.scala
new file mode 100644
index 000000000..0c9ed12bb
--- /dev/null
+++ b/tests/neg/customArgs/overloadsOnAbstractTypes.scala
@@ -0,0 +1,22 @@
+
+class Test1 {
+ type A
+ type B <: A
+
+ def foo(): A = ???
+ def foo(): A = ??? // error
+
+ def bar(): A = ???
+ def bar(): B = ??? // error
+}
+
+class Test2 {
+ type A
+ type B <: A
+
+ def foo(x: A) = ???
+ def foo(x: A) = ??? // error
+
+ def bar(x: A) = ???
+ def bar(x: B) = ??? // error
+}
diff --git a/tests/patmat/i2253.scala b/tests/patmat/i2253.scala
new file mode 100644
index 000000000..8394a86df
--- /dev/null
+++ b/tests/patmat/i2253.scala
@@ -0,0 +1,7 @@
+sealed trait S
+object O extends S
+trait T
+
+class Test {
+ def m(s: S { val x: Int }) = s match { case _: T => ; }
+} \ No newline at end of file
diff --git a/tests/patmat/i2254.scala b/tests/patmat/i2254.scala
new file mode 100644
index 000000000..23dd8ad70
--- /dev/null
+++ b/tests/patmat/i2254.scala
@@ -0,0 +1,6 @@
+object Test {
+ type OrAlias = Int | Float
+
+ def m(s: OrAlias | String) = s match {
+ case _: Int => ; case _: Float => ; case _: String => ; }
+} \ No newline at end of file
diff --git a/tests/pos/i2152.scala b/tests/pos/i2152.scala
new file mode 100644
index 000000000..2171a487e
--- /dev/null
+++ b/tests/pos/i2152.scala
@@ -0,0 +1,7 @@
+class Contra[-D](task: AnyRef)
+object Test {
+ def narrow(task: AnyRef): Contra[task.type] = new Contra(task)
+ def ident[Before](elems: Contra[Before]): Contra[Before] = elems
+ val foo = null
+ ident(narrow(foo))
+}