@@ -61,6 +61,7 @@ l / l2 // error: `/` is not a member of Logarithm
6161### Bounds For Opaque Type Aliases
6262
6363Opaque type aliases can also come with bounds. Example:
64+
6465``` scala
6566object Access :
6667
@@ -85,11 +86,12 @@ object Access:
8586
8687end Access
8788```
89+
8890The ` Access ` object defines three opaque type aliases:
8991
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".
9395
9496Outside the ` Access ` object, values of type ` Permissions ` may be combined using the ` & ` operator,
9597where ` 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`
106108` Permission ` type has an upper bound ` Permissions & PermissionChoice ` . This makes
107109it known outside the ` Access ` object that ` Permission ` is a subtype of the other
108110two types. Hence, the following usage scenario type-checks.
111+
109112``` scala
110113object User :
111114 import Access ._
@@ -116,16 +119,17 @@ object User:
116119 val rwItem = Item (ReadWrite )
117120 val noItem = Item (NoPermission )
118121
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 ))
121124
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 ))
124127
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 ))
127130end User
128131```
132+
129133On the other hand, the call ` roItem.rights.isOneOf(ReadWrite) ` would give a type error
130134since ` Permissions ` and ` PermissionChoice ` are different, unrelated types outside ` Access ` .
131135
0 commit comments