@@ -76,17 +76,17 @@ class A extends C[A] with D
7676class B extends C [B ] with D with E
7777```
7878
79- The join of ` A | B ` is ` C[A | B] with D `
79+ The join of ` A | B ` is ` C[A | B] & D `
8080
8181## Type inference
8282
83- When inferring the result type of a definition (` val ` , ` var ` , or ` def ` ), if the
84- type we are about to infer is a union type, we replace it by its join.
83+ When inferring the result type of a definition (` val ` , ` var ` , or ` def ` ) and the
84+ type we are about to infer is a union type, then we replace it by its join.
8585Similarly, when instantiating a type argument, if the corresponding type
8686parameter is not upper-bounded by a union type and the type we are about to
8787instantiate is a union type, we replace it by its join. This mirrors the
8888treatment of singleton types which are also widened to their underlying type
89- unless explicitly specified. and the motivation is the same: inferring types
89+ unless explicitly specified. The motivation is the same: inferring types
9090which are "too precise" can lead to unintuitive typechecking issues later on.
9191
9292Note: Since this behavior limits the usability of union types, it might
@@ -127,6 +127,14 @@ trait B { def hello: String }
127127def test (x : A | B ) = x.hello // error: value `hello` is not a member of A | B
128128```
129129
130+ On the otherhand, the following would be allowed
131+ ``` scala
132+ trait C { def hello : String }
133+ trait A extends C with D
134+ trait B extends C with E
135+
136+ def test (x : A | B ) = x.hello // ok as `hello` is a member of the join of A | B which is C
137+
130138## Exhaustivity checking
131139
132140If the selector of a pattern match is a union type , the match is considered
0 commit comments