Skip to content

Commit 10f9c36

Browse files
committed
Also exclude when param is alias type
1 parent 97a711c commit 10f9c36

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,9 @@ object RefChecks {
11481148
def strippedResultType = Applications.stripImplicit(tp.stripPoly, wildcardOnly = true).resultType
11491149
def firstExplicitParamTypes = Applications.stripImplicit(tp.stripPoly, wildcardOnly = true).firstParamTypes
11501150
def hasImplicitParams = tp.stripPoly match { case mt: MethodType => mt.isImplicitMethod case _ => false }
1151+
def isAnyAlias =
1152+
val denot = tp.typeSymbol.denot
1153+
denot.isAliasType || denot.isOpaqueAlias
11511154
val target = sym.info.firstExplicitParamTypes.head // required for extension method, the putative receiver
11521155
val methTp = sym.info.strippedResultType // skip leading implicits and the "receiver" parameter
11531156
def hidden =
@@ -1159,14 +1162,14 @@ object RefChecks {
11591162
if memberIsImplicit then methTp.stripPoly.firstParamTypes
11601163
else methTp.firstExplicitParamTypes
11611164

1162-
paramTps.isEmpty || memberIsImplicit && !methTp.hasImplicitParams || {
1165+
paramTps.isEmpty || memberIsImplicit && !methTp.hasImplicitParams || !paramTps.exists(_.typeSymbol.denot.isOpaqueAlias) && {
11631166
val memberParamTps = member.info.stripPoly.firstParamTypes
11641167
!memberParamTps.isEmpty
11651168
&& memberParamTps.lengthCompare(paramTps) == 0
11661169
&& memberParamTps.lazyZip(paramTps).forall((m, x) => x frozen_<:< m)
11671170
}
11681171
.exists
1169-
if !target.typeSymbol.denot.isAliasType && !target.typeSymbol.denot.isOpaqueAlias && hidden
1172+
if !target.isAnyAlias && hidden
11701173
then report.warning(ExtensionNullifiedByMember(sym, target.typeSymbol), sym.srcPos)
11711174
end checkExtensionMethods
11721175

tests/warn/opaque-overwarn.scala

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
package reproduction.opaqueoverwarning
3+
4+
opaque type FromEnd = Int
5+
object FromEnd:
6+
inline def apply(i: Int): FromEnd = i
7+
extension (fe: FromEnd)
8+
inline def value: Int = fe
9+
10+
// Warning appears when extension is in same namespace as opaque type
11+
// under 3.5.0-RC3 (and 3.6.0 nightly)
12+
extension [A](a: Array[A])
13+
inline def apply(fe: FromEnd): A =
14+
a(a.length - 1 - FromEnd.value(fe))
15+
16+
object Main:
17+
def run(): Unit =
18+
val xs = Array(1, 2, 3)
19+
20+
println(s"First element = ${xs(0)}")
21+
println(s"Last element = ${xs(FromEnd(0))}")
22+
23+
def main(args: Array[String]): Unit =
24+
run()

0 commit comments

Comments
 (0)