diff options
author | Martin Odersky <odersky@gmail.com> | 2015-12-14 17:16:34 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-12-14 17:16:34 +0100 |
commit | 503011f5749e7c21ab4f3b5eca8c2f9b0a1b37a6 (patch) | |
tree | 3b46b102d632e53eed4ad6bbcccee9b3bae70607 /src/dotty/tools/dotc/typer/RefChecks.scala | |
parent | 86e35e48bb7916b6c2e35147973d2572a29b93c3 (diff) | |
download | dotty-503011f5749e7c21ab4f3b5eca8c2f9b0a1b37a6.tar.gz dotty-503011f5749e7c21ab4f3b5eca8c2f9b0a1b37a6.tar.bz2 dotty-503011f5749e7c21ab4f3b5eca8c2f9b0a1b37a6.zip |
Check types for overriding conditions.
Closes #241 -- that took a while!
Diffstat (limited to 'src/dotty/tools/dotc/typer/RefChecks.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/RefChecks.scala | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/typer/RefChecks.scala b/src/dotty/tools/dotc/typer/RefChecks.scala index 44d5ee576..4bd02b356 100644 --- a/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/src/dotty/tools/dotc/typer/RefChecks.scala @@ -172,8 +172,8 @@ object RefChecks { val sym1 = sym.underlyingSymbol def info = self.memberInfo(sym1) i"${if (showLocation) sym1.showLocated else sym1}${ - if (sym1.isAliasType) i", which equals $info" - else if (sym1.isAbstractType) i" with bounds $info" + if (sym1.isAliasType) i", which equals ${info.bounds.hi}" + else if (sym1.isAbstractType) i" with bounds$info" else if (sym1.is(Module)) "" else if (sym1.isTerm) i" of type $info" else "" @@ -229,6 +229,18 @@ object RefChecks { (if (otherAccess == "") "public" else "at least " + otherAccess)) } + def compatibleTypes = + if (member.isType) { // intersection of bounds to refined types must be nonempty + member.is(BaseTypeArg) || + (memberTp <:< otherTp) || { + val jointBounds = (memberTp.bounds & otherTp.bounds).bounds + jointBounds.lo <:< jointBounds.hi + } + } + else + isDefaultGetter(member.name) || // default getters are not checked for compatibility + memberTp.overrides(otherTp) + //Console.println(infoString(member) + " overrides " + infoString(other) + " in " + clazz);//DEBUG // return if we already checked this combination elsewhere @@ -321,9 +333,7 @@ object RefChecks { overrideError("cannot be used here - term macros cannot override abstract methods") } else if (other.is(Macro) && !member.is(Macro)) { // (1.10) overrideError("cannot be used here - only term macros can override term macros") - } else if (member.isTerm && !isDefaultGetter(member.name) && !(memberTp overrides otherTp)) { - // types don't need to have their bounds in an overriding relationship - // since we automatically form their intersection when selecting. + } else if (!compatibleTypes) { overrideError("has incompatible type" + err.whyNoMatchStr(memberTp, otherTp)) } else { checkOverrideDeprecated() |