diff --git a/NewSource/SocordiaC/Compilation/Listeners/Body/IfStatementListener.cs b/NewSource/SocordiaC/Compilation/Listeners/Body/IfStatementListener.cs index af437a19..3cb632bb 100644 --- a/NewSource/SocordiaC/Compilation/Listeners/Body/IfStatementListener.cs +++ b/NewSource/SocordiaC/Compilation/Listeners/Body/IfStatementListener.cs @@ -10,6 +10,7 @@ public class IfStatementListener : Listener(node.Condition); cond = NegateCondition(cond); context.Builder.ForkIf(cond, (builder, block) => diff --git a/NewSource/SocordiaC/Compilation/Listeners/Body/WhileStatementListener.cs b/NewSource/SocordiaC/Compilation/Listeners/Body/WhileStatementListener.cs index 4998491b..804bc7cc 100644 --- a/NewSource/SocordiaC/Compilation/Listeners/Body/WhileStatementListener.cs +++ b/NewSource/SocordiaC/Compilation/Listeners/Body/WhileStatementListener.cs @@ -27,6 +27,7 @@ protected override void ListenToNode(BodyCompilation context, WhileStatement nod body.SetBranch(condBlk); var cond = Utils.CreateValue(node.Condition, context); + cond.EnsureType(node.Condition); condBlk.SetBranch(new BranchInst(cond, body, after)); context.Builder.SetPosition(after); diff --git a/NewSource/SocordiaC/Compilation/ValueExtensions.cs b/NewSource/SocordiaC/Compilation/ValueExtensions.cs new file mode 100644 index 00000000..d8ca00c8 --- /dev/null +++ b/NewSource/SocordiaC/Compilation/ValueExtensions.cs @@ -0,0 +1,13 @@ +namespace Socordia.Compilation; + +public static class ValueExtensions +{ + public static void EnsureType(this Value value, AstNode node) + { + //ToDo: fix this + if (value.Type != typeof(T)) + { + node.AddError($"Expected value of type {type}, but got {value.Type}"); + } + } +} \ No newline at end of file