Skip to content

Commit

Permalink
self-referencing inferred sets no longer crash the compiler.
Browse files Browse the repository at this point in the history
This is in many respects a hack but it will work until the v3 type system is merged.
Fixes #383
  • Loading branch information
McJones committed Jan 24, 2024
1 parent 28ea663 commit d8a3b70
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Enums in JSON schema are type sensitive, so a warning will be issued for types that have capital letters. To fix these warnings, change your type names in your `.ysls.json` file to be lowercase. (These warnings have no impact on your Yarn script editing experience or runtime behaviour.)
- Empty nodes will no longer be included in the compiled output
- a warning diagnostic will be generated for each empty node
- Fixed a bug where set-referencing inferred value set statements would crash the compiler

### Removed

Expand Down
15 changes: 14 additions & 1 deletion YarnSpinner.Compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Yarn.Compiler
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Antlr4.Runtime;
using Antlr4.Runtime.Tree;
using static Yarn.Instruction.Types;
Expand Down Expand Up @@ -291,6 +290,20 @@ public static CompilationResult Compile(CompilationJob compilationJob)
diagnostics.Add(hmm.diagnostic);
}

// 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);
foreach (var group in duplicateInferredVars)
{
var groupMessage = group.Select(d => $"\"{d.SourceFileName}\" on line {d.SourceFileLine}");
var message = $"\"{group.Key}\" has had its default value inferred in multiple places: " + String.Join(", ", groupMessage);
diagnostics.Add(new Diagnostic(message, Diagnostic.DiagnosticSeverity.Error));
}
// removing all the duplicate keys
var duplicateKeys = duplicateInferredVars.Select(g => g.Key);
knownVariableDeclarations.Where(d => duplicateKeys.Contains(d.Name));

// adding in the warnings about empty nodes
var empties = AddErrorsForEmptyNodes(parsedFiles, ref diagnostics);

Expand Down

0 comments on commit d8a3b70

Please sign in to comment.