string fix

This commit is contained in:
nub31
2025-09-12 23:13:48 +02:00
parent 20160229f9
commit 214ac6826d
3 changed files with 6 additions and 7 deletions

View File

@@ -758,6 +758,7 @@ public class QBEGenerator
private static string EmitBinaryInstructionForOperator(BinaryOperator op, TypeNode type)
{
// todo(nub31): Add support for string concatenation. Currently this expects ints or floats and will treat strings as ints
return op switch
{
BinaryOperator.RightShift => type switch

View File

@@ -358,13 +358,13 @@ public sealed class TypeChecker
case BinaryOperatorSyntax.Plus:
{
var left = CheckExpression(expression.Left);
if (left.Type is IntTypeNode or FloatTypeNode or StringTypeNode or StringTypeNode)
if (left.Type is IntTypeNode or FloatTypeNode or StringTypeNode or CStringTypeNode)
{
var right = CheckExpression(expression.Right, left.Type);
return new BinaryExpressionNode(left.Type, left, op, right);
}
throw new TypeCheckerException(Diagnostic.Error("The plus operator must be used with int, float or string types").At(expression.Left).Build());
throw new TypeCheckerException(Diagnostic.Error("The plus operator must be used with int, float, cstring or string types").At(expression.Left).Build());
}
case BinaryOperatorSyntax.Minus:
case BinaryOperatorSyntax.Multiply:

View File

@@ -9,12 +9,10 @@ export struct Human
extern "main" func main(args: []cstring): i64
{
let x = [1]Human
let x: cstring = "test"
x[0] = {
name = "oliver"
}
x = x + "uwu"
puts(x[0].name)
puts(x)
return 0
}