diff --git a/NewSource/Socordia.CodeAnalysis/AST/TypeNames/NoTypeName.cs b/NewSource/Socordia.CodeAnalysis/AST/TypeNames/NoTypeName.cs index 2250f175..7d2b6d82 100644 --- a/NewSource/Socordia.CodeAnalysis/AST/TypeNames/NoTypeName.cs +++ b/NewSource/Socordia.CodeAnalysis/AST/TypeNames/NoTypeName.cs @@ -1,3 +1,8 @@ namespace Socordia.CodeAnalysis.AST.TypeNames; -public class NoTypeName : TypeName; \ No newline at end of file +public class NoTypeName : TypeName +{ + public static readonly NoTypeName Instance { get; } = new NoTypeName(); + + private NoTypeName() { } +} \ No newline at end of file diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/VariableStatementParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/VariableStatementParser.cs index 7bafa12e..394951ec 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/VariableStatementParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/Statements/VariableStatementParser.cs @@ -11,7 +11,7 @@ public static AstNode Parse(TokenIterator iterator, Parser parser) var keywordToken = iterator.Prev; var isMutable = false; - TypeName? type = new NoTypeName(); + TypeName? type = NoTypeName.Instance; Token mutableToken = null; diff --git a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/TypeNameParser.cs b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/TypeNameParser.cs index 075064ba..e1276cef 100644 --- a/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/TypeNameParser.cs +++ b/NewSource/Socordia.CodeAnalysis/Parsing/ParsePoints/TypeNameParser.cs @@ -82,7 +82,7 @@ public static TypeName Parse(Parser parser) parser.AddError("Expected Identifier, TupleType or Function-Signature as TypeLiteral, but got " + TokenIterator.GetTokenRepresentation(iterator.Current.Type)); - typeNode = new NoTypeName(); + typeNode = NoTypeName.Instance; iterator.NextToken(); } diff --git a/NewSource/SocordiaC/Compilation/Listeners/Body/Lowering/SwapLowerer.cs b/NewSource/SocordiaC/Compilation/Listeners/Body/Lowering/SwapLowerer.cs index 0cd3f7b0..1ad302b9 100644 --- a/NewSource/SocordiaC/Compilation/Listeners/Body/Lowering/SwapLowerer.cs +++ b/NewSource/SocordiaC/Compilation/Listeners/Body/Lowering/SwapLowerer.cs @@ -17,7 +17,7 @@ public class SwapLowerer : Replacer //todo: implement a swap by introducting a new temp variable and test it var tmpName = Utils.GenerateIdentifier(); - var tmp = new VariableStatement(tmpName, new NoTypeName(), new Identifier(leftId.Name), false); + var tmp = new VariableStatement(tmpName, NoTypeName.Instance, new Identifier(leftId.Name), false); var left = new BinaryOperatorExpression("=", new Identifier(leftId.Name), new Identifier(rightId.Name)); var right = new BinaryOperatorExpression("=", new Identifier(rightId.Name), new Identifier(tmpName));