summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sources/scalac/typechecker/Analyzer.java9
-rw-r--r--test/files/neg/bounds.check4
-rw-r--r--test/files/neg/bounds.scala12
-rw-r--r--test/neg/bounds.check4
-rw-r--r--test/neg/bounds.scala12
5 files changed, 39 insertions, 2 deletions
diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java
index eb9758b198..1e8ec9daa9 100644
--- a/sources/scalac/typechecker/Analyzer.java
+++ b/sources/scalac/typechecker/Analyzer.java
@@ -1644,12 +1644,15 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
if (pt != Type.ErrorType) error(tree.pos, ex.msg);
return tree.setType(Type.ErrorType);
}
+/*
if (!(tree.type instanceof Type.MethodType))
tree = make.Apply(tree.pos, tree, Tree.EMPTY_ARRAY)
.setType(tree.type);
+*/
}
} else if (clazz.isSubClass(definitions.SEQ_CLASS)) {
// set type to instantiated sequence class constructor
+ // todo: should we admit even supertypes of the target type?
Type seqtp = pt.baseType(clazz);
if (seqtp != Type.NoType) {
tree.type = seqConstructorType(seqtp, pt);
@@ -2031,8 +2034,10 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
int i = 0;
while (i < tparams.length &&
(context.delayArgs ||
- argtypes[i].isSubType(
- tparams[i].info().subst(tparams, argtypes))))
+ (argtypes[i].isSubType(
+ tparams[i].info().subst(tparams, argtypes)) &&
+ tparams[i].loBound().subst(tparams, argtypes)
+ .isSubType(argtypes[i]))))
i++;
if (i == tparams.length) {
return copy.TypeApply(tree, fn1, args1)
diff --git a/test/files/neg/bounds.check b/test/files/neg/bounds.check
new file mode 100644
index 0000000000..0f4693da88
--- /dev/null
+++ b/test/files/neg/bounds.check
@@ -0,0 +1,4 @@
+bounds.scala:11: constructor A of type [T >: I](T)A[T] cannot be applied to [T]
+class B[T >: J](init: T) extends A[T](init) {
+ ^
+one error found
diff --git a/test/files/neg/bounds.scala b/test/files/neg/bounds.scala
new file mode 100644
index 0000000000..f9fbeaa674
--- /dev/null
+++ b/test/files/neg/bounds.scala
@@ -0,0 +1,12 @@
+class I {
+ def i(): Unit = {}
+}
+class J extends I {
+ def j(): Unit = {}
+}
+class A[T >: I](init: T) {
+ var y: T = new B();
+ class B() extends I {}
+}
+class B[T >: J](init: T) extends A[T](init) {
+}
diff --git a/test/neg/bounds.check b/test/neg/bounds.check
new file mode 100644
index 0000000000..0f4693da88
--- /dev/null
+++ b/test/neg/bounds.check
@@ -0,0 +1,4 @@
+bounds.scala:11: constructor A of type [T >: I](T)A[T] cannot be applied to [T]
+class B[T >: J](init: T) extends A[T](init) {
+ ^
+one error found
diff --git a/test/neg/bounds.scala b/test/neg/bounds.scala
new file mode 100644
index 0000000000..f9fbeaa674
--- /dev/null
+++ b/test/neg/bounds.scala
@@ -0,0 +1,12 @@
+class I {
+ def i(): Unit = {}
+}
+class J extends I {
+ def j(): Unit = {}
+}
+class A[T >: I](init: T) {
+ var y: T = new B();
+ class B() extends I {}
+}
+class B[T >: J](init: T) extends A[T](init) {
+}