File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -1156,6 +1156,11 @@ object RefChecks {
11561156 *
11571157 * If the extension method is nullary, it is always hidden by a member of the same name.
11581158 * (Either the member is nullary, or the reference is taken as the eta-expansion of the member.)
1159+ *
1160+ * This check is in lieu of a more expensive use-site check that an application failed to use an extension.
1161+ * That check would account for accessibility and opacity. As a limitation, this check considers
1162+ * only public members, a target receiver that is not an alias, and corresponding method parameters
1163+ * that are either both opaque types or both not.
11591164 */
11601165 def checkExtensionMethods (sym : Symbol )(using Context ): Unit =
11611166 if sym.is(Extension ) && ! sym.nextOverriddenSymbol.exists then
@@ -1179,7 +1184,9 @@ object RefChecks {
11791184 val memberParamTps = member.info.stripPoly.firstParamTypes
11801185 ! memberParamTps.isEmpty
11811186 && memberParamTps.lengthCompare(paramTps) == 0
1182- && memberParamTps.lazyZip(paramTps).forall((m, x) => x frozen_<:< m)
1187+ && memberParamTps.lazyZip(paramTps).forall: (m, x) =>
1188+ m.typeSymbol.denot.isOpaqueAlias == x.typeSymbol.denot.isOpaqueAlias
1189+ && (x frozen_<:< m)
11831190 }
11841191 }
11851192 .exists
Original file line number Diff line number Diff line change 1+
2+ import scala .io .Source
3+
4+ object Lengths :
5+ opaque type Length = Int
6+ object Length :
7+ def apply (i : Int ): Length = i
8+ extension (source : Source )
9+ def take (length : Length ): IndexedSeq [Char ] = // no warn
10+ source.take(length).to(IndexedSeq )
11+ end Lengths
12+
13+ trait Taken :
14+ def take (n : Lengths .Length ): Taken = ???
15+
16+ object Lengthy :
17+ import Lengths .*
18+ extension (taken : Taken ) def take (n : Length ): Taken = ??? // warn
19+
20+ @ main def test () = println :
21+ import Lengths .*
22+ val src = Source .fromString(" hello, world" )
23+ val len = Length (" hello" .length)
24+ src.take(len)
You can’t perform that action at this time.
0 commit comments