Bladeren bron

Make externally known variables unassignable.

Herby Vojčík 4 jaren geleden
bovenliggende
commit
e25f7b9973
4 gewijzigde bestanden met toevoegingen van 29 en 1 verwijderingen
  1. 18 0
      lang/src/Compiler-Semantic.js
  2. 4 0
      lang/src/Compiler-Semantic.st
  3. 6 1
      lang/src/Compiler-Tests.js
  4. 1 0
      lang/src/Compiler-Tests.st

+ 18 - 0
lang/src/Compiler-Semantic.js

@@ -1431,6 +1431,24 @@ return true;
 }; }),
 $globals.ExternallyKnownVar);
 
+$core.addMethod(
+$core.method({
+selector: "isImmutable",
+protocol: "testing",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "isImmutable\x0a\x09^ true",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: []
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+return true;
+
+}; }),
+$globals.ExternallyKnownVar);
+
 
 
 $core.addClass("InstanceVar", $globals.ScopeVar, [], "Compiler-Semantic");

+ 4 - 0
lang/src/Compiler-Semantic.st

@@ -325,6 +325,10 @@ I am a variable known externally (not in method scope).!
 
 isExternallyKnownVar
 	^ true
+!
+
+isImmutable
+	^ true
 ! !
 
 ScopeVar subclass: #InstanceVar

+ 6 - 1
lang/src/Compiler-Tests.js

@@ -2283,7 +2283,7 @@ selector: "testInvalidAssignment",
 protocol: "tests",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "testInvalidAssignment\x0a\x09self shouldntInstall: 'foo:a a:=1' andRaise: InvalidAssignmentError.\x0a\x09self shouldntInstall: 'foo false:=1' andRaise: InvalidAssignmentError.\x0a\x09self shouldntInstall: 'foo Number:=1' andRaise: InvalidAssignmentError\x0a",
+source: "testInvalidAssignment\x0a\x09self shouldntInstall: 'foo:a a:=1' andRaise: InvalidAssignmentError.\x0a\x09self shouldntInstall: 'foo false:=1' andRaise: InvalidAssignmentError.\x0a\x09self shouldntInstall: 'foo console:=1' andRaise: InvalidAssignmentError.\x0a\x09self shouldntInstall: 'foo Number:=1' andRaise: InvalidAssignmentError\x0a",
 referencedClasses: ["InvalidAssignmentError"],
 //>>excludeEnd("ide");
 pragmas: [],
@@ -2303,6 +2303,11 @@ return $core.withContext(function($ctx1) {
 ,$ctx1.sendIdx["shouldntInstall:andRaise:"]=2
 //>>excludeEnd("ctx");
 ][0];
+[$self._shouldntInstall_andRaise_("foo console:=1",$globals.InvalidAssignmentError)
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+,$ctx1.sendIdx["shouldntInstall:andRaise:"]=3
+//>>excludeEnd("ctx");
+][0];
 $self._shouldntInstall_andRaise_("foo Number:=1",$globals.InvalidAssignmentError);
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);

+ 1 - 0
lang/src/Compiler-Tests.st

@@ -594,6 +594,7 @@ shouldntInstall: aString andRaise: anErrorClass
 testInvalidAssignment
 	self shouldntInstall: 'foo:a a:=1' andRaise: InvalidAssignmentError.
 	self shouldntInstall: 'foo false:=1' andRaise: InvalidAssignmentError.
+	self shouldntInstall: 'foo console:=1' andRaise: InvalidAssignmentError.
 	self shouldntInstall: 'foo Number:=1' andRaise: InvalidAssignmentError
 !