Skip to content

Commit 47cd8d4

Browse files
authored
Merge pull request #9938 from dotty-staging/fix-#9735
Fix #9735: Tighten opaque types check
2 parents 38ba6e1 + 079b4f9 commit 47cd8d4

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,8 +888,8 @@ class Namer { typer: Typer =>
888888
val unsafeInfo = if (isDerived) rhsBodyType else abstracted(rhsBodyType)
889889

890890
def opaqueToBounds(info: Type): Type =
891-
if sym.isOpaqueAlias && tparamSyms.isEmpty && info.typeParams.nonEmpty then
892-
report.error(em"opaque type alias must be fully applied", rhs.srcPos)
891+
if sym.isOpaqueAlias && info.typeParams.nonEmpty && info.hkResult.typeParams.nonEmpty then
892+
report.error(em"opaque type alias cannot have multiple type parameter lists", rhs.srcPos)
893893
sym.opaqueToBounds(info, rhs1, tparamSyms)
894894

895895
if (isDerived) sym.info = unsafeInfo

docs/docs/reference/other-new-features/opaques-details.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ object o {
4646
def id(x: o.T): o.T = x
4747
```
4848

49+
### Type Parameters of Opaque Types
50+
51+
Opaque type aliases can have a single type parameter list. The following aliases
52+
are well-formed
53+
```scala
54+
opaque type F[T] = (T, T)
55+
opaque type G = [T] =>> List[T]
56+
```
57+
but the following are not:
58+
```scala
59+
opaque type BadF[T] = [U] =>> (T, U)
60+
opaque type BadG = [T] =>> [U] => (T, U)
61+
```
62+
4963
### Translation of Equality
5064

5165
Comparing two values of opaque type with `==` or `!=` normally uses universal equality,

tests/neg/i9735.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait Two[A, B]
2+
3+
opaque type U[A] = [B] =>> Two[A, B] // error: opaque type alias cannot have multiple type parameter lists // error: cannot instantiate
4+
opaque type T = [A] =>> [B] =>> String // error: opaque type alias cannot have multiple type parameter lists
5+
opaque type S = [B] =>> String // ok
6+
opaque type IArray[+T] = Array[? <: T] // ok
7+
opaque type S2[B] = String // ok
8+
9+
opaque type BadF[T] = [U] =>> (T, U) // error
10+
opaque type BadG = [T] =>> [U] =>> (T, U) // error
11+
12+

0 commit comments

Comments
 (0)