Skip to content

Commit 0dcb5e8

Browse files
committed
Fix underlyingClassRef for hk types
This gives us the right error message if we try to instantiate an hk opaque type with `new`.
1 parent 44f6142 commit 0dcb5e8

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,8 @@ object Types {
11661166
else if (tp.symbol.isAliasType) tp.underlying.underlyingClassRef(refinementOK)
11671167
else NoType
11681168
case tp: AppliedType =>
1169-
tp.superType.underlyingClassRef(refinementOK)
1169+
if (tp.tycon.isLambdaSub) NoType
1170+
else tp.superType.underlyingClassRef(refinementOK)
11701171
case tp: AnnotatedType =>
11711172
tp.underlying.underlyingClassRef(refinementOK)
11721173
case tp: RefinedType =>

tests/neg/alloc-abstract.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Test[T] {
2+
type U <: T
3+
4+
type Foo[T] = Array[T]
5+
6+
new T // error: not a class type
7+
new T() // error: not a class type
8+
new U // error: not a class type
9+
new U() // error: not a class type
10+
new IArray[String] // error: not a class type
11+
new IArray[String]() // error: not a class type
12+
new IArray[String](10) // error: not a class type // error: too mamy arguments
13+
14+
new Foo[String](10) // ok
15+
}

tests/neg/parser-stability-21.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class x0[x1[]] // error
2-
extends x1[ // error
2+
extends x1[
33
// error

0 commit comments

Comments
 (0)