File tree 4 files changed +49
-16
lines changed
compiler/src/dotty/tools/dotc/typer
4 files changed +49
-16
lines changed Original file line number Diff line number Diff line change @@ -216,12 +216,11 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
216
216
case methType : MethodType =>
217
217
// apply the result type constraint, unless method type is dependent
218
218
val resultApprox = resultTypeApprox(methType)
219
- val savedConstraint = ctx.typerState.constraint
220
219
if (! constrainResult(resultApprox, resultType))
221
220
if (ctx.typerState.isCommittable)
222
221
// defer the problem until after the application;
223
222
// it might be healed by an implicit conversion
224
- assert(ctx.typerState.constraint eq savedConstraint )
223
+ ( )
225
224
else
226
225
fail(err.typeMismatchMsg(methType.resultType, resultType))
227
226
// match all arguments with corresponding formal parameters
Original file line number Diff line number Diff line change @@ -54,20 +54,23 @@ object ProtoTypes {
54
54
/** Check that the result type of the current method
55
55
* fits the given expected result type.
56
56
*/
57
- def constrainResult (mt : Type , pt : Type )(implicit ctx : Context ): Boolean = pt match {
58
- case pt : FunProto =>
59
- mt match {
60
- case mt : MethodType =>
61
- constrainResult(resultTypeApprox(mt), pt.resultType)
62
- case _ =>
63
- true
64
- }
65
- case _ : ValueTypeOrProto if ! disregardProto(pt) =>
66
- isCompatible(normalize(mt, pt), pt)
67
- case pt : WildcardType if pt.optBounds.exists =>
68
- isCompatible(normalize(mt, pt), pt)
69
- case _ =>
70
- true
57
+ def constrainResult (mt : Type , pt : Type )(implicit ctx : Context ): Boolean = {
58
+ val savedConstraint = ctx.typerState.constraint
59
+ val res = pt match {
60
+ case pt : FunProto =>
61
+ mt match {
62
+ case mt : MethodType => constrainResult(resultTypeApprox(mt), pt.resultType)
63
+ case _ => true
64
+ }
65
+ case _ : ValueTypeOrProto if ! disregardProto(pt) =>
66
+ isCompatible(normalize(mt, pt), pt)
67
+ case pt : WildcardType if pt.optBounds.exists =>
68
+ isCompatible(normalize(mt, pt), pt)
69
+ case _ =>
70
+ true
71
+ }
72
+ if (! res) ctx.typerState.constraint = savedConstraint
73
+ res
71
74
}
72
75
}
73
76
Original file line number Diff line number Diff line change
1
+ class Foo [T ]
2
+
3
+ trait Prepend {
4
+ type Out
5
+ }
6
+
7
+ object Test {
8
+ def foo ()(implicit ev : Prepend ): Foo [ev.Out ] = ???
9
+
10
+ def test : Unit = {
11
+ foo(): Foo [Any ] // error: found: Prepend => Foo[_] required: Foo[Any]
12
+
13
+ }
14
+
15
+ implicit val p : Prepend = ???
16
+ }
Original file line number Diff line number Diff line change
1
+ class Foo [+ T ]
2
+
3
+ trait Prepend {
4
+ type Out
5
+ }
6
+
7
+ object Test {
8
+ def foo ()(implicit ev : Prepend ): Foo [ev.Out ] = ???
9
+
10
+ def test : Unit = {
11
+ foo(): Foo [Any ]
12
+ }
13
+
14
+ implicit val p : Prepend = ???
15
+ }
You can’t perform that action at this time.
0 commit comments