File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -3272,12 +3272,21 @@ class Typer extends Namer
3272
3272
case IgnoredProto (_ : FunOrPolyProto ) => false
3273
3273
case _ => true
3274
3274
}
3275
+ // If the expected type is a selection of an extension method, deepen it
3276
+ // to also propagate the argument type (which is the receiver we have
3277
+ // typechecked already). This is needed for i8311.scala. Doing so
3278
+ // for all expected types does not work since it would block the case
3279
+ // where we have an argument that must be converted with another
3280
+ // implicit conversion to the receiver type.
3281
+ def sharpenedPt = pt match
3282
+ case pt : SelectionProto if pt.name.isExtensionName => pt.deepenProto
3283
+ case _ => pt
3275
3284
var resMatch : Boolean = false
3276
3285
wtp match {
3277
3286
case wtp : ExprType =>
3278
3287
readaptSimplified(tree.withType(wtp.resultType))
3279
3288
case wtp : MethodType if wtp.isImplicitMethod &&
3280
- ({ resMatch = constrainResult(tree.symbol, wtp, pt ); resMatch } || ! functionExpected) =>
3289
+ ({ resMatch = constrainResult(tree.symbol, wtp, sharpenedPt ); resMatch } || ! functionExpected) =>
3281
3290
if (resMatch || ctx.mode.is(Mode .ImplicitsEnabled ))
3282
3291
adaptNoArgsImplicitMethod(wtp)
3283
3292
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