From 7c5e36b80e111d17910dbf122c02a458377656d1 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 18 Dec 2016 19:29:02 +0100 Subject: More lenient handling of mixed parameterless and nullary methods When faced with a denotation that combines parameterless and nullary method definitions (toString is a common example), ignore any redundant () applications. --- compiler/src/dotty/tools/dotc/core/Types.scala | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'compiler/src/dotty/tools/dotc/core') diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 069b4f60d..df1e68944 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -217,6 +217,14 @@ object Types { case _ => false } + /** Is this the type of a method with a leading empty parameter list? + */ + def isNullaryMethod(implicit ctx: Context): Boolean = this match { + case MethodType(Nil, _) => true + case tp: PolyType => tp.resultType.isNullaryMethod + case _ => false + } + /** Is this an alias TypeBounds? */ def isAlias: Boolean = this.isInstanceOf[TypeAlias] -- cgit v1.2.3 From 8e2a8db09680a4a5b715b02fa3491f683db9574d Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 19 Dec 2016 14:12:12 +0100 Subject: Make `msg` in testScala2Mode by-name. Avoids potentially expensive string assembly operations. --- compiler/src/dotty/tools/dotc/core/TypeOps.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler/src/dotty/tools/dotc/core') diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index f134412a7..5f9263009 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -546,7 +546,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object. def dynamicsEnabled = featureEnabled(defn.LanguageModuleClass, nme.dynamics) - def testScala2Mode(msg: String, pos: Position) = { + def testScala2Mode(msg: => String, pos: Position) = { if (scala2Mode) migrationWarning(msg, pos) scala2Mode } -- cgit v1.2.3 From dbdb123ae7180b66e5d29ad4dd89b746641a3457 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 19 Dec 2016 16:35:48 +0100 Subject: Fix subtyping of hk types with wildcard arguments Argument comparison of hk types did not take into account that the compared types could have themselves wildcard arguments. --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 10 ++++++++-- tests/pos/hkwild.scala | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tests/pos/hkwild.scala (limited to 'compiler/src/dotty/tools/dotc/core') diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 334306f19..8930983f3 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -757,8 +757,14 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { if (args1.isEmpty) args2.isEmpty else args2.nonEmpty && { val v = tparams.head.paramVariance - (v > 0 || isSubType(args2.head, args1.head)) && - (v < 0 || isSubType(args1.head, args2.head)) + def isSub(tp1: Type, tp2: Type) = tp2 match { + case tp2: TypeBounds => + tp2.contains(tp1) + case _ => + (v > 0 || isSubType(tp2, tp1)) && + (v < 0 || isSubType(tp1, tp2)) + } + isSub(args1.head, args2.head) } && isSubArgs(args1.tail, args2.tail, tparams) /** Test whether `tp1` has a base type of the form `B[T1, ..., Tn]` where diff --git a/tests/pos/hkwild.scala b/tests/pos/hkwild.scala new file mode 100644 index 000000000..49bea7d01 --- /dev/null +++ b/tests/pos/hkwild.scala @@ -0,0 +1,6 @@ +class Test[T1](val x: T1) { + def invert[El1, CC1[X]](implicit w1: T1 <:< CC1[El1]) = { + val buf: CC1[_] = w1(x) + ??? + } +} -- cgit v1.2.3