File tree 2 files changed +43
-1
lines changed
compiler/src/dotty/tools/dotc/core
2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -985,7 +985,7 @@ object SymDenotations {
985
985
if (is(Module )) sourceModule
986
986
else if (isOpaqueAlias)
987
987
info match {
988
- case TypeAlias (TypeRef (TermRef ( prefix, _) , _)) => prefix.termSymbol
988
+ case TypeAlias (TypeRef (prefix : TermRef , _)) => prefix.termSymbol
989
989
}
990
990
else registeredCompanion.sourceModule
991
991
Original file line number Diff line number Diff line change
1
+ object Library {
2
+
3
+ opaque type Nat = Int
4
+
5
+ object Nat {
6
+ def apply (n : Int ): Nat = {
7
+ require(n >= 0 )
8
+ n
9
+ }
10
+ def times (x : Nat , y : Nat ): Nat = x * y
11
+ def toInt (n : Nat ): Int = n
12
+
13
+ implicit class NatOps (val self : Nat ) extends AnyVal {
14
+ def * (other : Nat ): Nat = self * other
15
+ def toInt : Int = self.asInstanceOf
16
+ }
17
+ }
18
+ }
19
+
20
+ object User extends App {
21
+ import Library ._
22
+
23
+ val x = Nat (3 )
24
+ val y = Nat (4 )
25
+
26
+ val a = x * y // inferred type is Library.Nat.Nat
27
+ val b = double1(x) // inferred type is Library.Nat
28
+ val c = double2(x) // inferred type is Library.Nat.Nat
29
+
30
+ assert(a.toInt == 12 ) // works
31
+ // assert(b.toInt == 6) // error: toInt is not a member of Library.Nat
32
+ assert(c.toInt == 6 ) // works
33
+
34
+ def double0 (n : Nat ): Nat = n * Nat (2 ) // ok
35
+
36
+ def double3 (n : Nat ): Nat = Nat .NatOps (n) * Nat (2 ) // ok
37
+
38
+
39
+ def double1 (n : Nat .Nat ): Nat = n * Nat (2 ) // output type is incorrect
40
+
41
+ def double2 (n : Nat .Nat ): Nat .Nat = n * Nat (2 ) // works
42
+ }
You can’t perform that action at this time.
0 commit comments