@@ -109,8 +109,8 @@ By _reasonable usage_, we include the following use cases (but not restricted to
109
109
110
110
## Principles and Rules
111
111
112
- To achieve the goals, we uphold two fundamental principles:
113
- _ stackability_ and _ monotonicity _ .
112
+ To achieve the goals, we uphold three fundamental principles:
113
+ _ stackability_ , _ monotonicity _ and _ scopability _ .
114
114
115
115
Stackability means that objects are initialized in stack order: if the
116
116
object ` b ` is created during the initialization of object ` a ` , then
@@ -146,6 +146,28 @@ typestate_ to ensure soundness in the presence of aliasing
146
146
[ 1] . Otherwise, either soundness will be compromised or we have to
147
147
disallow the usage of already initialized fields.
148
148
149
+ Scopability means that given any environment ρ (which are the value
150
+ bindings for method parameters) for evaluating an expression ` e ` , the
151
+ resulting value is either transitively initialized or it may only
152
+ reach uninitialized objects that are reachable from ρ in the heap
153
+ before the evaluation. Control effects such as exceptions break this
154
+ property, as the following example shows:
155
+
156
+ ``` scala
157
+ class MyException (val b : B ) extends Exception (" " )
158
+ class A {
159
+ val b = try { new B } catch { case myEx : MyException => myEx.b }
160
+ println(b.a)
161
+ }
162
+ class B {
163
+ throw new MyException (this )
164
+ val a : Int = 1
165
+ }
166
+ ```
167
+
168
+ In the code above, the control effect teleport the uninitialized value
169
+ wrapped in an exception. In the implementation, we avoid the problem
170
+ by ensuring that the values that are thrown must be transitively initialized.
149
171
150
172
With the established principles and design goals, following rules are imposed:
151
173
0 commit comments