Skip to content

Commit

Permalink
Show error when passing "-> myVar" as a divert target rather than jus…
Browse files Browse the repository at this point in the history
…t "myVar". Slightly confusing :-/
  • Loading branch information
joethephish committed Sep 14, 2016
1 parent 6360931 commit d9f7f51
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions inklecate/ParsedHierarchy/DivertTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
22 changes: 22 additions & 0 deletions tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit d9f7f51

Please sign in to comment.