diff --git a/inklecate/ParsedHierarchy/DivertTarget.cs b/inklecate/ParsedHierarchy/DivertTarget.cs index b8caf0d0..0d104a10 100644 --- a/inklecate/ParsedHierarchy/DivertTarget.cs +++ b/inklecate/ParsedHierarchy/DivertTarget.cs @@ -85,6 +85,17 @@ public override void ResolveReferences (Story context) usageContext = usageParent; } + // Example ink for this class: + // + // VAR x = -> blah + // + // ...which means that "blah" is expected to be a literal stitch target rather + // than a variable name. We can't really intelligently recover from this (e.g. if blah happens to + // contain a divert target itself) since really we should be generating a variable reference + // rather than a concrete DivertTarget, so we list it as an error. + if (_runtimeDivert.hasVariableTarget) + Error ("Since '"+divert.target.dotSeparatedComponents+"' is a variable, it shouldn't be preceded by '->' here."); + _runtimeDivertTargetValue.targetPath = _runtimeDivert.targetPath; } diff --git a/tests/Tests.cs b/tests/Tests.cs index 7519de20..cf8d1601 100644 --- a/tests/Tests.cs +++ b/tests/Tests.cs @@ -2383,6 +2383,28 @@ This content is inaccessible. Assert.AreEqual (string.Empty, story.ContinueMaximally ()); } + [Test ()] + public void TestWrongVariableDivertTargetReference () + { + var storyStr = + @" +-> go_to_broken(-> SOMEWHERE) + +== go_to_broken(-> b) + -> go_to(-> b) // INSTEAD OF: -> go_to(b) + +== go_to(-> a) + -> a + +== SOMEWHERE == +Should be able to get here! +-> DONE +"; + CompileStringWithoutRuntime (storyStr, testingErrors:true); + + Assert.IsTrue (HadError ("it shouldn't be preceded by '->'")); + } + // Helper compile function protected Story CompileString(string str, bool countAllVisits = false, bool testingErrors = false) {