Skip to content

Commit

Permalink
Merge pull request #14665 from dotty-staging/fix-14659
Browse files Browse the repository at this point in the history
Disallow overriding opaque type aliases
  • Loading branch information
bishabosha committed Mar 11, 2022
2 parents 995f4f0 + 06c1b1a commit fb235fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Expand Up @@ -305,7 +305,7 @@ object RefChecks {
def info = self.memberInfo(sym1)
val infoStr =
if (sym1.isAliasType) i", which equals ${info.bounds.hi}"
else if (sym1.isAbstractOrParamType) i" with bounds$info"
else if (sym1.isAbstractOrParamType && info != TypeBounds.empty) i" with bounds$info"
else if (sym1.is(Module)) ""
else if (sym1.isTerm) i" of type $info"
else ""
Expand Down Expand Up @@ -430,6 +430,10 @@ object RefChecks {
// direct overrides were already checked on completion (see Checking.chckWellFormed)
// the test here catches indirect overriddes between two inherited base types.
overrideError("cannot be used here - class definitions cannot be overridden")
else if (other.isOpaqueAlias)
// direct overrides were already checked on completion (see Checking.chckWellFormed)
// the test here catches indirect overriddes between two inherited base types.
overrideError("cannot be used here - opaque type aliases cannot be overridden")
else if (!other.is(Deferred) && member.isClass)
overrideError("cannot be used here - classes can only override abstract types")
else if other.isEffectivelyFinal then // (1.2)
Expand Down
13 changes: 13 additions & 0 deletions tests/neg/i14659.scala
@@ -0,0 +1,13 @@
trait Foo {
opaque type Out = Int
def out1: Out
def out2: Out = out1
}

object Bar extends Foo {
override opaque type Out = String // error
override def out1 = "abc"
}

@main def run() =
val x = Bar.out2

0 comments on commit fb235fc

Please sign in to comment.