@@ -61,6 +61,7 @@ l / l2 // error: `/` is not a member of Logarithm
61
61
### Bounds For Opaque Type Aliases
62
62
63
63
Opaque type aliases can also come with bounds. Example:
64
+
64
65
``` scala
65
66
object Access :
66
67
@@ -85,11 +86,12 @@ object Access:
85
86
86
87
end Access
87
88
```
89
+
88
90
The ` Access ` object defines three opaque type aliases:
89
91
90
- - ` Permission ` , representing a single permission,
91
- - ` Permissions ` , representing a set of permissions with the meaning "all of these permissions granted",
92
- - ` PermissionChoice ` , representing a set of permissions with the meaning "at least one of these permissions granted".
92
+ - ` Permission ` , representing a single permission,
93
+ - ` Permissions ` , representing a set of permissions with the meaning "all of these permissions granted",
94
+ - ` PermissionChoice ` , representing a set of permissions with the meaning "at least one of these permissions granted".
93
95
94
96
Outside the ` Access ` object, values of type ` Permissions ` may be combined using the ` & ` operator,
95
97
where ` x & y ` means "all permissions in ` x ` * and* in ` y ` granted".
@@ -106,6 +108,7 @@ All three opaque type aliases have the same underlying representation type `Int`
106
108
` Permission ` type has an upper bound ` Permissions & PermissionChoice ` . This makes
107
109
it known outside the ` Access ` object that ` Permission ` is a subtype of the other
108
110
two types. Hence, the following usage scenario type-checks.
111
+
109
112
``` scala
110
113
object User :
111
114
import Access ._
@@ -116,16 +119,17 @@ object User:
116
119
val rwItem = Item (ReadWrite )
117
120
val noItem = Item (NoPermission )
118
121
119
- assert( roItem.rights.is(ReadWrite ) == false )
120
- assert( roItem.rights.isOneOf(ReadOrWrite ) == true )
122
+ assert(! roItem.rights.is(ReadWrite ))
123
+ assert(roItem.rights.isOneOf(ReadOrWrite ))
121
124
122
- assert( rwItem.rights.is(ReadWrite ) == true )
123
- assert( rwItem.rights.isOneOf(ReadOrWrite ) == true )
125
+ assert(rwItem.rights.is(ReadWrite ))
126
+ assert(rwItem.rights.isOneOf(ReadOrWrite ))
124
127
125
- assert( noItem.rights.is(ReadWrite ) == false )
126
- assert( noItem.rights.isOneOf(ReadOrWrite ) == false )
128
+ assert(! noItem.rights.is(ReadWrite ))
129
+ assert(! noItem.rights.isOneOf(ReadOrWrite ))
127
130
end User
128
131
```
132
+
129
133
On the other hand, the call ` roItem.rights.isOneOf(ReadWrite) ` would give a type error
130
134
since ` Permissions ` and ` PermissionChoice ` are different, unrelated types outside ` Access ` .
131
135
0 commit comments