File tree 3 files changed +63
-2
lines changed
compiler/src/dotty/tools/dotc/typer
3 files changed +63
-2
lines changed Original file line number Diff line number Diff line change @@ -1168,8 +1168,9 @@ object RefChecks {
1168
1168
def strippedResultType = Applications .stripImplicit(tp.stripPoly, wildcardOnly = true ).resultType
1169
1169
def firstExplicitParamTypes = Applications .stripImplicit(tp.stripPoly, wildcardOnly = true ).firstParamTypes
1170
1170
def hasImplicitParams = tp.stripPoly match { case mt : MethodType => mt.isImplicitMethod case _ => false }
1171
- val target = sym.info.firstExplicitParamTypes.head // required for extension method, the putative receiver
1171
+ val target = sym.info.firstExplicitParamTypes.head.typeSymbol.info // required for extension method, the putative receiver
1172
1172
val methTp = sym.info.strippedResultType // skip leading implicits and the "receiver" parameter
1173
+
1173
1174
def hidden =
1174
1175
target.nonPrivateMember(sym.name)
1175
1176
.filterWithPredicate:
@@ -1190,7 +1191,7 @@ object RefChecks {
1190
1191
}
1191
1192
}
1192
1193
.exists
1193
- if ! target.typeSymbol.isOpaqueAlias && hidden
1194
+ if hidden
1194
1195
then report.warning(ExtensionNullifiedByMember (sym, target.typeSymbol), sym.srcPos)
1195
1196
end checkExtensionMethods
1196
1197
Original file line number Diff line number Diff line change
1
+ -- [E194] Potential Issue Warning: tests/warn/i22232.scala:3:23 --------------------------------------------------------
2
+ 3 | extension (c: C) def equals(that: Any): Boolean = false // warn
3
+ | ^
4
+ | Extension method equals will never be selected from type C
5
+ | because C already has a member with the same name and compatible parameter types.
6
+ |
7
+ | longer explanation available when compiling with `-explain`
8
+ -- [E194] Potential Issue Warning: tests/warn/i22232.scala:9:25 --------------------------------------------------------
9
+ 9 | extension (d: D) def equals(that: Any): Boolean = false // warn
10
+ | ^
11
+ | Extension method equals will never be selected from type C
12
+ | because C already has a member with the same name and compatible parameter types.
13
+ |
14
+ | longer explanation available when compiling with `-explain`
15
+ -- [E194] Potential Issue Warning: tests/warn/i22232.scala:13:38 -------------------------------------------------------
16
+ 13 | extension (arr: MyString[Byte]) def length: Int = 0 // warn
17
+ | ^
18
+ | Extension method length will never be selected from type String
19
+ | because String already has a member with the same name and compatible parameter types.
20
+ |
21
+ | longer explanation available when compiling with `-explain`
22
+ -- [E194] Potential Issue Warning: tests/warn/i22232.scala:17:46 -------------------------------------------------------
23
+ 17 | extension [T <: MyString[Byte]](arr: T) def length: Int = 0 // warn
24
+ | ^
25
+ | Extension method length will never be selected from type String
26
+ | because String already has a member with the same name and compatible parameter types.
27
+ |
28
+ | longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change
1
+ class C
2
+ object C :
3
+ extension (c : C ) def equals (that : Any ): Boolean = false // warn
4
+
5
+ object X :
6
+ class C
7
+ opaque type D <: C = C
8
+ object D :
9
+ extension (d : D ) def equals (that : Any ): Boolean = false // warn
10
+
11
+ object Upperbound1 :
12
+ opaque type MyString [+ T ] <: String = String
13
+ extension (arr : MyString [Byte ]) def length : Int = 0 // warn
14
+
15
+ object Upperbound2 :
16
+ opaque type MyString [+ T ] <: String = String
17
+ extension [T <: MyString [Byte ]](arr : T ) def length : Int = 0 // warn
18
+
19
+ object Upperbound3 :
20
+ opaque type MyString [+ T ] <: String = String
21
+ extension [T ](arr : T ) def length : Int = 0 // nowarn
22
+
23
+ object NonUpperbound1 :
24
+ opaque type MyString [+ T ] = String
25
+ extension (arr : MyString [Byte ]) def length : Int = 0 // nowarn
26
+ object NonUpperbound2 :
27
+ opaque type MyString [+ T ] = String
28
+ extension [T <: MyString [Byte ]](arr : T ) def length2 : Int = 0 // nowarn
29
+
30
+ object NonUpperbound3 :
31
+ opaque type MyString [+ T ] = String
32
+ extension [T ](arr : T ) def length : Int = 0 // nowarn
You can’t perform that action at this time.
0 commit comments