Skip to content

Commit

Permalink
Added a test for the new hack.
Browse files Browse the repository at this point in the history
Also reduced it's scope, it was also slurping up functions which we don't care about.
  • Loading branch information
McJones committed Jan 24, 2024
1 parent d8a3b70 commit 4888959
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion YarnSpinner.Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public static CompilationResult Compile(CompilationJob compilationJob)
// TODO: I am pretty sure this is made redundant by the v3 type system, will need to check if it's still needed.
// determining if there are any duplicate infered variables
// at this point this shouldn't happen, but if it has we need to error out now
var duplicateInferredVars = knownVariableDeclarations.GroupBy(d => d.Name).Where(g => g.Count() > 1);
var duplicateInferredVars = knownVariableDeclarations.Where(d => !(d.Type is FunctionType)).GroupBy(d => d.Name).Where(g => g.Count() > 1);
foreach (var group in duplicateInferredVars)
{
var groupMessage = group.Select(d => $"\"{d.SourceFileName}\" on line {d.SourceFileLine}");
Expand Down
17 changes: 17 additions & 0 deletions YarnSpinner.Tests/TypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -845,5 +845,22 @@ public void TestFunctionTypeBuilderCanBuildTypes() {
expectedFunctionType.Parameters[1].Should().Be(functionType.Parameters[1]);
expectedFunctionType.ReturnType.Should().Be(functionType.ReturnType);
}

[Fact]
public void TestSelfReferencingSetErrors()
{
// this test should fail on the v3 type system which is good, but for now I want to make sure its tested as is
// plus when this fails on v3 it's a good reminder to remove the hack
var source = CreateTestNode("<<set $badInference = $badInference + 1>>");

var result = Compiler.Compile(CompilationJob.CreateFromString("input", source));

// we should have one diagnostic
result.Diagnostics.Count().Should().Be(1);
// it's an error
result.Diagnostics.FirstOrDefault().Severity.Should().Be(Diagnostic.DiagnosticSeverity.Error);
// and it's the "I found this twice so don't know what to do" error
result.Diagnostics.Should().Contain(d => d.Message.Contains("\"$badInference\" has had its default value inferred in multiple places:"));
}
}
}

0 comments on commit 4888959

Please sign in to comment.