Fix void auto-return bug with empty stmts

This commit is contained in:
nub31
2025-09-08 20:51:35 +02:00
parent c4c533ffbd
commit 0098a8d7ee
2 changed files with 2 additions and 40 deletions

View File

@@ -363,7 +363,7 @@ public class QBEGenerator
EmitBlock(funcDef.Body); EmitBlock(funcDef.Body);
// Implicit return for void functions if no explicit return has been set // 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"); _writer.Indented("ret");
} }
@@ -400,7 +400,7 @@ public class QBEGenerator
EmitBlock(function.Body); EmitBlock(function.Body);
// Implicit return for void functions if no explicit return has been set // 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"); _writer.Indented("ret");
} }

View File

@@ -1,38 +0,0 @@
namespace NubLang;
public static class HexString
{
private static readonly HashSet<string> _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;
}
}