From 4888959007220bbaa7ae25d77ec371c5f9f18a55 Mon Sep 17 00:00:00 2001 From: Tim Nugent Date: Wed, 24 Jan 2024 15:44:15 +1100 Subject: [PATCH] Added a test for the new hack. Also reduced it's scope, it was also slurping up functions which we don't care about. --- YarnSpinner.Compiler/Compiler.cs | 2 +- YarnSpinner.Tests/TypeTests.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/YarnSpinner.Compiler/Compiler.cs b/YarnSpinner.Compiler/Compiler.cs index de6b36524..50ab97a36 100644 --- a/YarnSpinner.Compiler/Compiler.cs +++ b/YarnSpinner.Compiler/Compiler.cs @@ -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}"); diff --git a/YarnSpinner.Tests/TypeTests.cs b/YarnSpinner.Tests/TypeTests.cs index 53969a59e..6f14bf0a4 100644 --- a/YarnSpinner.Tests/TypeTests.cs +++ b/YarnSpinner.Tests/TypeTests.cs @@ -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("<>"); + + 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:")); + } } }