Skip to content

Commit

Permalink
Warn on bad extensions of aliases (#22362)
Browse files Browse the repository at this point in the history
Fixes #22233
  • Loading branch information
RoccoMathijn authored Jan 29, 2025
1 parent a5f7e1c commit 5fe57c2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ object RefChecks {
}
}
.exists
if !target.typeSymbol.denot.isAliasType && !target.typeSymbol.denot.isOpaqueAlias && hidden
if !target.typeSymbol.isOpaqueAlias && hidden
then report.warning(ExtensionNullifiedByMember(sym, target.typeSymbol), sym.srcPos)
end checkExtensionMethods

Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions tests/warn/i16743.check
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-- [E194] Potential Issue Warning: tests/warn/i16743.scala:90:8 --------------------------------------------------------
90 | def length() = 42 // warn This extension method will be shadowed by .length() on String.
| ^
| Extension method length will never be selected from type String
| because String already has a member with the same name and compatible parameter types.
|
| longer explanation available when compiling with `-explain`
-- [E194] Potential Issue Warning: tests/warn/i16743.scala:30:6 --------------------------------------------------------
30 | def t = 27 // warn
| ^
Expand Down
2 changes: 1 addition & 1 deletion tests/warn/i16743.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Depends:
object Depending:
extension (using depends: Depends)(x: depends.Thing)
def y = 42
def length() = 42 // nowarn see Quote above
def length() = 42 // warn This extension method will be shadowed by .length() on String.
def f(using d: Depends) = d.thing.y
def g(using d: Depends) = d.thing.length()

Expand Down
1 change: 1 addition & 0 deletions tests/warn/i22233.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extension (s: String) def length = 42 // warn

0 comments on commit 5fe57c2

Please sign in to comment.