summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala3
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala6
-rw-r--r--test/files/neg/t9008.check4
-rw-r--r--test/files/neg/t9008.scala3
-rw-r--r--test/files/neg/t9008b.check4
-rw-r--r--test/files/neg/t9008b.scala3
-rw-r--r--test/files/pos/t9008.scala5
7 files changed, 26 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index b13f9e94cc..9a34e8dfed 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -480,7 +480,8 @@ trait Contexts { self: Analyzer =>
// SI-8245 `isLazy` need to skip lazy getters to ensure `return` binds to the right place
c.enclMethod = if (isDefDef && !owner.isLazy) c else enclMethod
- if (tree != outer.tree) c(TypeConstructorAllowed) = false
+ if (tree != outer.tree)
+ c(TypeConstructorAllowed) = false
registerContext(c.asInstanceOf[analyzer.Context])
debuglog("[context] ++ " + c.unit + " / " + tree.summaryString)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 4d9a6a47ef..aaa75b5ee1 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -5207,7 +5207,11 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
def typedExistentialTypeTree(tree: ExistentialTypeTree) = {
val tree1 = typerWithLocalContext(context.makeNewScope(tree, context.owner)){
- _.typedExistentialTypeTree(tree, mode)
+ typer =>
+ if (context.inTypeConstructorAllowed)
+ typer.context.withinTypeConstructorAllowed(typer.typedExistentialTypeTree(tree, mode))
+ else
+ typer.typedExistentialTypeTree(tree, mode)
}
checkExistentialsFeature(tree1.pos, tree1.tpe, "the existential type")
tree1
diff --git a/test/files/neg/t9008.check b/test/files/neg/t9008.check
new file mode 100644
index 0000000000..c32bc41baf
--- /dev/null
+++ b/test/files/neg/t9008.check
@@ -0,0 +1,4 @@
+t9008.scala:2: error: type M takes type parameters
+ def x: List[M forSome { type M[_] }] = ???
+ ^
+one error found
diff --git a/test/files/neg/t9008.scala b/test/files/neg/t9008.scala
new file mode 100644
index 0000000000..c6a5389e42
--- /dev/null
+++ b/test/files/neg/t9008.scala
@@ -0,0 +1,3 @@
+object Test {
+ def x: List[M forSome { type M[_] }] = ???
+}
diff --git a/test/files/neg/t9008b.check b/test/files/neg/t9008b.check
new file mode 100644
index 0000000000..5e911fc138
--- /dev/null
+++ b/test/files/neg/t9008b.check
@@ -0,0 +1,4 @@
+t9008b.scala:2: error: type M takes type parameters
+ type T = M forSome { type M[_] }
+ ^
+one error found
diff --git a/test/files/neg/t9008b.scala b/test/files/neg/t9008b.scala
new file mode 100644
index 0000000000..58f9d0e8de
--- /dev/null
+++ b/test/files/neg/t9008b.scala
@@ -0,0 +1,3 @@
+object Test {
+ type T = M forSome { type M[_] }
+}
diff --git a/test/files/pos/t9008.scala b/test/files/pos/t9008.scala
new file mode 100644
index 0000000000..d11b8604f2
--- /dev/null
+++ b/test/files/pos/t9008.scala
@@ -0,0 +1,5 @@
+trait Monad[M[_]]
+
+object Test {
+ def x: Monad[M forSome { type M[_] }] = ???
+}