Disallow static fields access from outside instances

This commit is contained in:
Jaime Humberto Macias Bustamante
2025-06-17 12:33:32 -07:00
parent a4d2d4c788
commit 04a50580c6
2 changed files with 15 additions and 0 deletions
+1
View File
@@ -205,6 +205,7 @@ class CustomClassHandler implements IHScriptCustomConstructor implements IHScrip
return _class;
}
@:allow(hscript.Interp)
function hasField(name:String) {
return staticFields.contains(name);
}
+14
View File
@@ -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;