Disallow static fields access from outside instances
This commit is contained in:
@@ -205,6 +205,7 @@ class CustomClassHandler implements IHScriptCustomConstructor implements IHScrip
|
||||
return _class;
|
||||
}
|
||||
|
||||
@:allow(hscript.Interp)
|
||||
function hasField(name:String) {
|
||||
return staticFields.contains(name);
|
||||
}
|
||||
|
||||
@@ -1280,6 +1280,13 @@ class Interp {
|
||||
if (o == null)
|
||||
error(EInvalidAccess(f));
|
||||
|
||||
if(o is CustomClass) {
|
||||
if(cast(o, CustomClass).__class.hasField(f)) {
|
||||
var clsName = cast(o, CustomClass).className;
|
||||
error(ECustom('The field ${clsName}.${f} should be accessed in a static way.'));
|
||||
}
|
||||
}
|
||||
|
||||
var cls = Type.getClass(o);
|
||||
if (useRedirects && {
|
||||
var cl:Null<String> = getClassType(o, cls);
|
||||
@@ -1320,6 +1327,13 @@ class Interp {
|
||||
if (o == null)
|
||||
error(EInvalidAccess(f));
|
||||
|
||||
if(o is CustomClass) {
|
||||
if(cast(o, CustomClass).__class.hasField(f)) {
|
||||
var clsName = cast(o, CustomClass).className;
|
||||
error(ECustom('The field ${clsName}.${f} should be accessed in a static way.'));
|
||||
}
|
||||
}
|
||||
|
||||
if (useRedirects && {
|
||||
var cl:Null<String> = getClassType(o);
|
||||
cl != null && setRedirects.exists(cl) && (_setRedirect = setRedirects[cl]) != null;
|
||||
|
||||
Reference in New Issue
Block a user