Skip to content

Commit d989caf

Browse files
authored
Merge pull request #8412 from dotty-staging/fix-#8337
Fix #8337: Flag F-bounded opaque types as errors
2 parents ea71b2c + c3fd8e4 commit d989caf

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,8 +2596,8 @@ object Types {
25962596
/** Update the value of the lazyref, discarding the compute function `refFn`
25972597
* Can be called only as long as the ref is still undefined.
25982598
*/
2599-
def update(tp: Type) =
2600-
assert(myRef == null)
2599+
def update(tp: Type)(using ctx: Context) =
2600+
assert(myRef == null || ctx.reporter.errorsReported)
26012601
myRef = tp
26022602
computed = true
26032603
refFn = null

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The general form of a (monomorphic) opaque type alias is
2020
```scala
2121
opaque type T >: L <: U = R
2222
```
23-
where the lower bound `L` and the upper bound `U` may be missing, in which case they are assumed to be `scala.Nothing` and `scala.Any`, respectively. If bounds are given, it is checked that the right hand side `R` conforms to them, i.e. `L <: R` and `R <: U`.
23+
where the lower bound `L` and the upper bound `U` may be missing, in which case they are assumed to be `scala.Nothing` and `scala.Any`, respectively. If bounds are given, it is checked that the right hand side `R` conforms to them, i.e. `L <: R` and `R <: U`. F-bounds are not supported for opaque types: `T` is not allowed to appear in `L` or `U`.
2424

2525
Inside the scope of the alias definition, the alias is transparent: `T` is treated
2626
as a normal alias of `R`. Outside its scope, the alias is treated as the abstract type

tests/neg/i8337.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
trait Foo[F <: Foo[F]]
2+
class Bar extends Foo[Bar]
3+
4+
object Q { // error: recursion limit exceeded
5+
opaque type X <: Foo[X] = Bar // error: out of bounds
6+
}

0 commit comments

Comments
 (0)