File tree 3 files changed +30
-2
lines changed
compiler/src/dotty/tools/dotc/typer 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -3251,12 +3251,21 @@ class Typer extends Namer
3251
3251
case IgnoredProto (_ : FunOrPolyProto ) => false
3252
3252
case _ => true
3253
3253
}
3254
+ // If the expected type is a selection of an extension method, deepen it
3255
+ // to also propagate the argument type (which is the receiver we have
3256
+ // typechecked already). This is needed for i8311.scala. Doing so
3257
+ // for all expected types does not work since it would block the case
3258
+ // where we have an argument that must be converted with another
3259
+ // implicit conversion to the receiver type.
3260
+ def sharpenedPt = pt match
3261
+ case pt : SelectionProto if pt.name.isExtensionName => pt.deepenProto
3262
+ case _ => pt
3254
3263
var resMatch : Boolean = false
3255
3264
wtp match {
3256
3265
case wtp : ExprType =>
3257
3266
readaptSimplified(tree.withType(wtp.resultType))
3258
3267
case wtp : MethodType if wtp.isImplicitMethod &&
3259
- ({ resMatch = constrainResult(tree.symbol, wtp, pt ); resMatch } || ! functionExpected) =>
3268
+ ({ resMatch = constrainResult(tree.symbol, wtp, sharpenedPt ); resMatch } || ! functionExpected) =>
3260
3269
if (resMatch || ctx.mode.is(Mode .ImplicitsEnabled ))
3261
3270
adaptNoArgsImplicitMethod(wtp)
3262
3271
else
Original file line number Diff line number Diff line change
1
+
2
+ trait Show [O ]:
3
+ extension (o : O )
4
+ def show : String
5
+
6
+ class Box [A ]
7
+ class Foo
8
+
9
+ object test :
10
+
11
+ given box [A ](using Show [A ]) as Show [Box [A ]] = _.toString
12
+ given foo as Show [Foo ] = _.toString
13
+
14
+ def run (s : Box [Box [Foo ]]): Unit =
15
+ val x = summon[Show [Box [Box [Foo ]]]]
16
+ x.extension_show(s)
17
+ val r : String = box.extension_show(s)
18
+ println(s " step: ${box[Box [Foo ]].extension_show(s)}" )
19
+ println(s " step: ${s.show}" )
Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ object ExtMethods:
104
104
summon[Ord [Lst [Lst [Int ]]]]
105
105
106
106
assert(Lst .ord[Lst [Int ]].extension_less(xss)(Lst (Lst (3 ))))
107
- // fails type inference: assert(xss `less` Lst(Lst(3)))
107
+ assert(xss `less` Lst (Lst (3 )))
108
108
assert(xss.flatten `less` Lst (3 ))
109
109
110
110
extension (s : String )
You can’t perform that action at this time.
0 commit comments