@@ -229,8 +229,7 @@ class LocalVariable implements Stashable {
229
229
230
230
function touchVariable ( context : AnalysisContext , token : Token , isAssignment : boolean ) : boolean {
231
231
if ( isAssignment ) {
232
- if ( this . _isConstant && context . getTopBlock ( ) . localVariableStatuses . getStatus ( this ) != LocalVariableStatuses . UNSET ) {
233
- context . errors . push ( new CompileError ( token , "assignment of read-only variable" ) ) ;
232
+ if ( ! this . canAssignment ( context , token ) ) {
234
233
return false ;
235
234
}
236
235
context . getTopBlock ( ) . localVariableStatuses . setStatus ( this ) ;
@@ -259,6 +258,15 @@ class LocalVariable implements Stashable {
259
258
return true ;
260
259
}
261
260
261
+ function canAssignment ( context : AnalysisContext , token : Token ) : boolean {
262
+ if ( this . _isConstant && context . getTopBlock ( ) . localVariableStatuses . getStatus ( this ) != LocalVariableStatuses . UNSET ) {
263
+ context . errors . push ( new CompileError ( token , "assignment of read-only variable" ) ) ;
264
+ return false ;
265
+ }
266
+ return true ;
267
+ }
268
+
269
+
262
270
override function toString ( ) : string {
263
271
return this . _name . getValue ( ) + " : " + this . _type . toString ( ) ;
264
272
}
@@ -324,8 +332,13 @@ class ArgumentDeclaration extends LocalVariable {
324
332
this . _defaultValue = defaultValue ;
325
333
}
326
334
335
+ function constructor ( name : Token , type : Type , isConst : boolean , defaultValue : Expression ) {
336
+ super ( name , type , isConst ) ;
337
+ this . _defaultValue = defaultValue ;
338
+ }
339
+
327
340
function clone ( ) : ArgumentDeclaration {
328
- return new ArgumentDeclaration ( this . _name , this . _type , Util . cloneNullable ( this . _defaultValue ) ) ;
341
+ return new ArgumentDeclaration ( this . _name , this . _type , this . _isConstant , Util . cloneNullable ( this . _defaultValue ) ) ;
329
342
}
330
343
331
344
function getDefaultValue ( ) : Expression {
@@ -334,13 +347,20 @@ class ArgumentDeclaration extends LocalVariable {
334
347
335
348
override function _instantiate ( instantiationContext : InstantiationContext ) : ArgumentDeclaration {
336
349
var type = this . _type != null ? this . _type . instantiate ( instantiationContext , false ) : null ;
337
- return new ArgumentDeclaration ( this . _name , type , this . _defaultValue ) ;
350
+ return new ArgumentDeclaration ( this . _name , type , this . _isConstant , this . _defaultValue ) ;
338
351
}
339
352
340
353
override function instantiateAndPush ( instantiationContext : InstantiationContext ) : ArgumentDeclaration {
341
354
return super . instantiateAndPush ( instantiationContext ) as ArgumentDeclaration ;
342
355
}
343
356
357
+ override function canAssignment ( context : AnalysisContext , token : Token ) : boolean {
358
+ if ( this . _isConstant ) {
359
+ context . errors . push ( new CompileError ( token , "The preceding argument is read-only within the default argument expression" ) ) ;
360
+ return false ;
361
+ }
362
+ return true ;
363
+ }
344
364
}
345
365
346
366
class LocalVariableStatuses {
0 commit comments