From 496b2a74ce324405f1e96eb9c1d32565dcfee4ad Mon Sep 17 00:00:00 2001 From: ZZYZX Date: Fri, 17 Feb 2017 20:04:40 +0200 Subject: [PATCH] Disallow const qualifier for classes --- src/scripting/zscript/zcc_compile.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 2d2f84492a..0c77b46f89 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -2128,6 +2128,13 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool if (f->Flags & ZCC_ClearScope) varflags = (varflags&~(VARF_Play | VARF_UI)); + // [ZZ] supporting const self for actors is quite a cumbersome task because there's no concept of a const pointer (?) + // either way, it doesn't make sense, because you can call any method on a readonly class instance. + if ((f->Flags & ZCC_FuncConst) && !(c->Type()->IsKindOf(RUNTIME_CLASS(PStruct)))) + { + Error(f, "'Const' on a method can only be used in structs"); + } + if ((f->Flags & ZCC_VarArg) && !(f->Flags & ZCC_Native)) { Error(f, "'VarArg' can only be used with native methods"); @@ -2173,6 +2180,12 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool } if (varflags & VARF_Override) varflags |= VARF_Virtual; // Now that the flags are checked, make all override functions virtual as well. + // [ZZ] this doesn't make sense either. + if ((varflags&(VARF_ReadOnly | VARF_Method)) == VARF_ReadOnly) // non-method const function + { + Error(f, "'Const' on a static method is not supported"); + } + // you can't have a const function belonging to either ui or play. // const is intended for plain data to signify that you can call a method on readonly variable. if ((f->Flags & ZCC_FuncConst) && (f->Flags & (ZCC_UIFlag | ZCC_Play)))