Skip to content

Commit

Permalink
Merge branch 'bugfixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
GGG-KILLER committed Mar 10, 2024
2 parents 95a74f1 + 308d4ff commit c9cae5c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Compilers/Lua/Portable/Parser/Lexer.Numbers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,12 @@ private void ParseHexadecimalNumber(ref TokenInfo info)
info.ValueKind = ValueKind.Complex;
info.ComplexValue = new Complex(0, result);
}
// We check for IntegerFormats.NotSupported because on places where integers aren't supported,
// numbers are parsed as doubles which means there's no overflow behavior so we shouldn't check
// for it either.
else if (isHexFloat || _options.SyntaxOptions.HexIntegerFormat == IntegerFormats.NotSupported)
{
if (!_options.SyntaxOptions.AcceptHexFloatLiterals)
if (isHexFloat && !_options.SyntaxOptions.AcceptHexFloatLiterals)
AddError(ErrorCode.ERR_HexFloatLiteralNotSupportedInVersion);

var result = 0d;
Expand Down
3 changes: 3 additions & 0 deletions src/Compilers/Lua/Portable/Syntax/SyntaxNormalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,9 @@ private TReturn WithTempState<TArg, TReturn>(Func<TArg, TReturn> func, TArg arg)
if (SyntaxFacts.IsKeyword(node.OperatorToken.Kind()))
AddSpaceAfterToken(node.OperatorToken);

if (node.OperatorToken.Kind() is SyntaxKind.MinusToken && node.Operand is UnaryExpressionSyntax { OperatorToken.RawKind: (int) SyntaxKind.MinusToken })
AddSpaceAfterToken(node.OperatorToken);

return base.VisitUnaryExpression(node);
}

Expand Down
34 changes: 33 additions & 1 deletion src/Compilers/Lua/Test/Portable/Lexical/RegressionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Xunit;
using Loretta.Test.Utilities;
using Xunit;

namespace Loretta.CodeAnalysis.Lua.UnitTests.Lexical
{
Expand All @@ -24,5 +25,36 @@ public void Lexer_Lexes_LongStringWithoutLeadingNewLine()
Assert.Equal(RawText, token.Text);
Assert.Equal(Value, token.Value);
}

[Fact]
[WorkItem(120, "https://github.com/LorettaDevs/Loretta/issues/120")]
[Trait("Type", TestType.Regression)]
[Trait("Category", "Lexer/Diagnostics")]
public void Lexer_Lexes_HexIntegersProperlyWhenPresetDoesntSupportIntegers()
{
const string RawText = "0X049bbe662";

var token = LexToken(RawText, LuaSyntaxOptions.Lua51);

Assert.Equal(SyntaxKind.NumericLiteralToken, token.Kind());
Assert.Equal(RawText, token.Text);
Assert.Equal((double) 0x049bbe662, token.Value);
Assert.False(token.ContainsDiagnostics);
}

[Fact]
[WorkItem(120, "https://github.com/LorettaDevs/Loretta/issues/120")]
[Trait("Type", TestType.Regression)]
[Trait("Category", "Lexer/Diagnostics")]
public void Lexer_Warns_AboutHexFloatsProperlyWhenPresetDoesntSupportIntegers()
{
const string RawText = "0X049bbe662.ff";

var token = LexToken(RawText, LuaSyntaxOptions.Lua51);

Assert.Equal(SyntaxKind.NumericLiteralToken, token.Kind());
Assert.Equal(RawText, token.Text);
Assert.True(token.ContainsDiagnostics);
}
}
}
15 changes: 15 additions & 0 deletions src/Compilers/Lua/Test/Portable/Syntax/SyntaxNormalizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,21 @@ public void SyntaxNormalizer_CorrectlyAddsLineBreaksAfterSingleLineComments(stri
AssertNormalizeCore(root, expected);
}

[Theory]
[WorkItem(122, "https://github.com/LorettaDevs/Loretta/issues/122")]
[InlineData("print( - - 2)", "print(- -2)")]
[InlineData("print( - - - 2)", "print(- - -2)")]
[InlineData("print( - - - - 2)", "print(- - - -2)")]
[InlineData("print( - - - - - 2)", "print(- - - - -2)")]
[InlineData("print( - - - - - - - - - - - - - 2)", "print(- - - - - - - - - - - - -2)")]
public void SyntaxNormalizer_CorrectlyAddsSpacesOnDoubleUnaryMinus(string input, string expected)
{
var tree = ParseAndValidate(input, s_luaParseOptions);
var root = tree.GetRoot();

AssertNormalizeCore(root, expected);
}

#region Class Implementation Details

private static void AssertNormalizeCore(SyntaxNode node, string expected)
Expand Down

0 comments on commit c9cae5c

Please sign in to comment.