Skip to content

Commit a5e44d8

Browse files
committed
Update return type inference
Scala 3 does not infer more precise types for the return type of overriding methods. This can be seen in the following example: ```scala type T type U <: T abstract class A{ def m: T } class B extends A{ def m = ??? : U } val res: U = (new B).m ```
1 parent ce595b8 commit a5e44d8

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

docs/_spec/04-basic-declarations-and-definitions.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,7 @@ sum(xs: _*)
612612
### Method Return Type Inference
613613

614614
A class member definition ´m´ that overrides some other method ´m'´ in a base class of ´C´ may leave out the return type, even if it is recursive.
615-
In this case, the return type ´R'´ of the overridden method ´m'´, seen as a member of ´C´, is taken as the return type of ´m´ for each recursive invocation of ´m´.
616-
That way, a type ´R´ for the right-hand side of ´m´ can be determined, which is then taken as the return type of ´m´.
617-
Note that ´R´ may be different from ´R'´, as long as ´R´ conforms to ´R'´.
615+
In this case, whether or not `m` is recursive, its return type will be the return type of ´m'´.
618616

619617
###### Example
620618
Assume the following definitions:

0 commit comments

Comments
 (0)