Skip to content

Commit fb235fc

Browse files
authored
Merge pull request #14665 from dotty-staging/fix-14659
Disallow overriding opaque type aliases
2 parents 995f4f0 + 06c1b1a commit fb235fc

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ object RefChecks {
305305
def info = self.memberInfo(sym1)
306306
val infoStr =
307307
if (sym1.isAliasType) i", which equals ${info.bounds.hi}"
308-
else if (sym1.isAbstractOrParamType) i" with bounds$info"
308+
else if (sym1.isAbstractOrParamType && info != TypeBounds.empty) i" with bounds$info"
309309
else if (sym1.is(Module)) ""
310310
else if (sym1.isTerm) i" of type $info"
311311
else ""
@@ -430,6 +430,10 @@ object RefChecks {
430430
// direct overrides were already checked on completion (see Checking.chckWellFormed)
431431
// the test here catches indirect overriddes between two inherited base types.
432432
overrideError("cannot be used here - class definitions cannot be overridden")
433+
else if (other.isOpaqueAlias)
434+
// direct overrides were already checked on completion (see Checking.chckWellFormed)
435+
// the test here catches indirect overriddes between two inherited base types.
436+
overrideError("cannot be used here - opaque type aliases cannot be overridden")
433437
else if (!other.is(Deferred) && member.isClass)
434438
overrideError("cannot be used here - classes can only override abstract types")
435439
else if other.isEffectivelyFinal then // (1.2)

tests/neg/i14659.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trait Foo {
2+
opaque type Out = Int
3+
def out1: Out
4+
def out2: Out = out1
5+
}
6+
7+
object Bar extends Foo {
8+
override opaque type Out = String // error
9+
override def out1 = "abc"
10+
}
11+
12+
@main def run() =
13+
val x = Bar.out2

0 commit comments

Comments
 (0)