Skip to content

Commit 5fe57c2

Browse files
authored
Warn on bad extensions of aliases (#22362)
Fixes #22233
1 parent a5f7e1c commit 5fe57c2

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ object RefChecks {
11901190
}
11911191
}
11921192
.exists
1193-
if !target.typeSymbol.denot.isAliasType && !target.typeSymbol.denot.isOpaqueAlias && hidden
1193+
if !target.typeSymbol.isOpaqueAlias && hidden
11941194
then report.warning(ExtensionNullifiedByMember(sym, target.typeSymbol), sym.srcPos)
11951195
end checkExtensionMethods
11961196

File renamed without changes.

tests/warn/i16743.check

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
-- [E194] Potential Issue Warning: tests/warn/i16743.scala:90:8 --------------------------------------------------------
2+
90 | def length() = 42 // warn This extension method will be shadowed by .length() on String.
3+
| ^
4+
| Extension method length will never be selected from type String
5+
| because String already has a member with the same name and compatible parameter types.
6+
|
7+
| longer explanation available when compiling with `-explain`
18
-- [E194] Potential Issue Warning: tests/warn/i16743.scala:30:6 --------------------------------------------------------
29
30 | def t = 27 // warn
310
| ^

tests/warn/i16743.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Depends:
8787
object Depending:
8888
extension (using depends: Depends)(x: depends.Thing)
8989
def y = 42
90-
def length() = 42 // nowarn see Quote above
90+
def length() = 42 // warn This extension method will be shadowed by .length() on String.
9191
def f(using d: Depends) = d.thing.y
9292
def g(using d: Depends) = d.thing.length()
9393

tests/warn/i22233.scala

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extension (s: String) def length = 42 // warn

0 commit comments

Comments
 (0)