From 0098a8d7eeee8d2369f877b1c726e049de271a50 Mon Sep 17 00:00:00 2001 From: nub31 Date: Mon, 8 Sep 2025 20:51:35 +0200 Subject: [PATCH] Fix void auto-return bug with empty stmts --- .../NubLang/Generation/QBE/QBEGenerator.cs | 4 +- src/compiler/NubLang/HexString.cs | 38 ------------------- 2 files changed, 2 insertions(+), 40 deletions(-) delete mode 100644 src/compiler/NubLang/HexString.cs diff --git a/src/compiler/NubLang/Generation/QBE/QBEGenerator.cs b/src/compiler/NubLang/Generation/QBE/QBEGenerator.cs index 9541faf..c6503c5 100644 --- a/src/compiler/NubLang/Generation/QBE/QBEGenerator.cs +++ b/src/compiler/NubLang/Generation/QBE/QBEGenerator.cs @@ -363,7 +363,7 @@ public class QBEGenerator EmitBlock(funcDef.Body); // Implicit return for void functions if no explicit return has been set - if (funcDef.Signature.ReturnType is VoidTypeNode && funcDef.Body.Statements is [.., not ReturnNode]) + if (funcDef.Signature.ReturnType is VoidTypeNode && funcDef.Body.Statements.LastOrDefault() is not ReturnNode) { _writer.Indented("ret"); } @@ -400,7 +400,7 @@ public class QBEGenerator EmitBlock(function.Body); // Implicit return for void functions if no explicit return has been set - if (function.Signature.ReturnType is VoidTypeNode && function.Body.Statements is [.., not ReturnNode]) + if (function.Signature.ReturnType is VoidTypeNode && function.Body.Statements.LastOrDefault() is not ReturnNode) { _writer.Indented("ret"); } diff --git a/src/compiler/NubLang/HexString.cs b/src/compiler/NubLang/HexString.cs deleted file mode 100644 index 0291111..0000000 --- a/src/compiler/NubLang/HexString.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace NubLang; - -public static class HexString -{ - private static readonly HashSet _used = []; - - private static readonly char[] StringChars = "0123456789abcdef".ToArray(); - - public static string CreateUnique(int length) - { - string hex; - - while (true) - { - hex = Create(length); - if (_used.Add(hex)) - { - break; - } - } - - return hex; - } - - public static string Create(int length) - { - var rand = new Random(); - var hexString = ""; - - for (var i = 0; i < length; i++) - { - var randIndex = rand.Next(0, StringChars.Length); - hexString += StringChars[randIndex]; - } - - return hexString; - } -} \ No newline at end of file