Skip to content

Commit ca0ef84

Browse files
authored
Merge pull request #8622 from dotty-staging/fix-#8617
Fix #8617: Check that there is no inheritance/definition shadowing
2 parents a0690e1 + 617b95c commit ca0ef84

File tree

26 files changed

+206
-64
lines changed

26 files changed

+206
-64
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ object desugar {
112112
val originalOwner = sym.owner
113113
def apply(tp: Type) = tp match {
114114
case tp: NamedType if tp.symbol.exists && (tp.symbol.owner eq originalOwner) =>
115-
val defctx = ctx.outersIterator.dropWhile(_.scope eq ctx.scope).next()
115+
val defctx = this.ctx.outersIterator.dropWhile(_.scope eq this.ctx.scope).next()
116116
var local = defctx.denotNamed(tp.name).suchThat(_.isParamOrAccessor).symbol
117117
if (local.exists) (defctx.owner.thisType select local).dealiasKeepAnnots
118118
else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ object Denotations {
12431243
throw new MergeError(sym1, sym2, sym1.info, sym2.info, pre) {
12441244
override def addendum(implicit ctx: Context) =
12451245
i"""
1246-
|they are both defined in ${sym1.effectiveOwner} but have matching signatures
1246+
|they are both defined in ${this.sym1.effectiveOwner} but have matching signatures
12471247
| ${denot1.info} and
12481248
| ${denot2.info}${super.addendum}"""
12491249
}

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3784,7 +3784,7 @@ object Parsers {
37843784
i"refinement cannot have default arguments"
37853785
case tree: ValOrDefDef =>
37863786
if tree.rhs.isEmpty then ""
3787-
else "refinement in cannot have a right-hand side"
3787+
else "refinement cannot have a right-hand side"
37883788
case tree: TypeDef =>
37893789
if !tree.isClassDef then ""
37903790
else "refinement cannot be a class or trait"

compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] {
5757
CyclicReferenceInvolvingID,
5858
CyclicReferenceInvolvingImplicitID,
5959
SuperQualMustBeParentID,
60-
AmbiguousImportID,
60+
AmbiguousReferenceID,
6161
MethodDoesNotTakeParametersId,
6262
AmbiguousOverloadID,
6363
ReassignmentToValID,

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ object messages {
250250
// these are usually easier to analyze.
251251
object reported extends TypeMap:
252252
def setVariance(v: Int) = variance = v
253-
val constraint = ctx.typerState.constraint
253+
val constraint = this.ctx.typerState.constraint
254254
def apply(tp: Type): Type = tp match
255255
case tp: TypeParamRef =>
256256
constraint.entry(tp) match
257257
case bounds: TypeBounds =>
258-
if variance < 0 then apply(ctx.typeComparer.fullUpperBound(tp))
259-
else if variance > 0 then apply(ctx.typeComparer.fullLowerBound(tp))
258+
if variance < 0 then apply(this.ctx.typeComparer.fullUpperBound(tp))
259+
else if variance > 0 then apply(this.ctx.typeComparer.fullLowerBound(tp))
260260
else tp
261261
case NoType => tp
262262
case instType => apply(instType)
@@ -1244,8 +1244,8 @@ object messages {
12441244

12451245
import typer.Typer.BindingPrec
12461246

1247-
class AmbiguousImport(name: Name, newPrec: BindingPrec, prevPrec: BindingPrec, prevCtx: Context)(implicit ctx: Context)
1248-
extends ReferenceMsg(AmbiguousImportID) {
1247+
class AmbiguousReference(name: Name, newPrec: BindingPrec, prevPrec: BindingPrec, prevCtx: Context)(implicit ctx: Context)
1248+
extends ReferenceMsg(AmbiguousReferenceID) {
12491249

12501250
/** A string which explains how something was bound; Depending on `prec` this is either
12511251
* imported by <tree>
@@ -1254,6 +1254,7 @@ object messages {
12541254
private def bindingString(prec: BindingPrec, whereFound: Context, qualifier: String = "") = {
12551255
val howVisible = prec match {
12561256
case BindingPrec.Definition => "defined"
1257+
case BindingPrec.Inheritance => "inherited"
12571258
case BindingPrec.NamedImport => "imported by name"
12581259
case BindingPrec.WildImport => "imported"
12591260
case BindingPrec.PackageClause => "found"
@@ -1266,18 +1267,21 @@ object messages {
12661267
}
12671268

12681269
def msg =
1269-
i"""|Reference to ${em"$name"} is ambiguous
1270+
i"""|Reference to ${em"$name"} is ambiguous,
12701271
|it is both ${bindingString(newPrec, ctx)}
12711272
|and ${bindingString(prevPrec, prevCtx, " subsequently")}"""
12721273

12731274
def explain =
12741275
em"""|The compiler can't decide which of the possible choices you
1275-
|are referencing with $name.
1276+
|are referencing with $name: A definition of lower precedence
1277+
|in an inner scope, or a definition with higher precedence in
1278+
|an outer scope.
12761279
|Note:
1277-
|- Definitions take precedence over imports
1278-
|- Named imports take precedence over wildcard imports
1279-
|- You may replace a name when imported using
1280-
| ${hl("import")} scala.{ $name => ${name.show + "Tick"} }
1280+
| - Definitions in an enclosing scope take precedence over inherited definitions
1281+
| - Definitions take precedence over imports
1282+
| - Named imports take precedence over wildcard imports
1283+
| - You may replace a name when imported using
1284+
| ${hl("import")} scala.{ $name => ${name.show + "Tick"} }
12811285
|"""
12821286
}
12831287

compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
138138
tp match {
139139
case tp: TypeRef if tp.symbol.isSplice =>
140140
if (tp.isTerm)
141-
ctx.error(i"splice outside quotes", pos)
141+
this.ctx.error(i"splice outside quotes", pos)
142142
if level > 0 then getQuoteTypeTags.getTagRef(tp.prefix.asInstanceOf[TermRef])
143143
else tp
144144
case tp: TypeRef if tp.symbol == defn.QuotedTypeClass.typeParams.head =>

0 commit comments

Comments
 (0)