From 814282fa0d45f8648e3aa6fb872bbc3c822a7891 Mon Sep 17 00:00:00 2001 From: arookas Date: Mon, 28 Dec 2015 14:31:51 -0500 Subject: [PATCH] Fixed: prevent recursive const definitions and assert for actual constancy. --- ssc/ast/nodes.variables.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ssc/ast/nodes.variables.cs b/ssc/ast/nodes.variables.cs index 2610150..30d39a8 100644 --- a/ssc/ast/nodes.variables.cs +++ b/ssc/ast/nodes.variables.cs @@ -74,6 +74,13 @@ : base(location) { } public override void Compile(sunContext context) { + // analyze the expression first. this does two things: + // 1) prevents recursion (i.e. the const referencing itself) + // 2) asserts actual constness + var flags = Expression.Analyze(context); + if (flags.HasFlag(sunExpressionFlags.Dynamic)) { + throw new sunConstantExpressionException(Expression); + } context.DeclareConstant(Constant, Expression); } }