fix(template): M2.7 review nits — comment-aware arg tokenizer + stricter numeric-literal inference (#20/#21)

SplitCallArguments now skips C# line (`//`) and block (`/* */`) comments when
tokenizing the argument list, so a comma inside a comment no longer produces a
spurious arg-count mismatch.  IsNumericLiteral now explicitly rejects tokens
whose first non-sign character is `_` or a letter (e.g. `_2`), and restricts
underscore digit-separators to positions after at least one digit, preventing
identifier-shaped tokens from being inferred as Integer/Float.
This commit is contained in:
Joseph Doherty
2026-06-16 05:21:23 -04:00
parent 958229e1f8
commit a8e9e9952d
2 changed files with 125 additions and 1 deletions
@@ -968,4 +968,92 @@ public class SemanticValidatorTests
Assert.DoesNotContain(result.Warnings,
w => w.Category == ValidationCategory.TriggerOperandType);
}
// ── M2.7 review nits — comment-aware arg tokenizer ─────────────────────
[Fact]
public void Validate_ArgSplit_LineCommentWithCommaInsideArgs_NoFalsePositive()
{
// A `//` line comment containing a comma must NOT be counted as an arg separator.
// "Target" expects (a: Integer) — one real arg; the comment comma is noise.
var config = new FlattenedConfiguration
{
InstanceUniqueName = "Instance1",
Scripts =
[
new ResolvedScript
{
CanonicalName = "Target",
Code = "var x = 1;",
ParameterDefinitions = "[{\"name\":\"a\",\"type\":\"Integer\"}]"
},
new ResolvedScript
{
CanonicalName = "Caller",
Code = "CallScript(\"Target\", 42 /* , extra */);"
}
]
};
var result = _sut.Validate(config);
Assert.DoesNotContain(result.Errors, e => e.Category == ValidationCategory.ParameterMismatch);
}
[Fact]
public void Validate_ArgSplit_BlockCommentWithCommaInsideArgs_NoFalsePositive()
{
// A `/* */` block comment containing a comma must NOT be counted as an arg separator.
var config = new FlattenedConfiguration
{
InstanceUniqueName = "Instance1",
Scripts =
[
new ResolvedScript
{
CanonicalName = "Target",
Code = "var x = 1;",
ParameterDefinitions = "[{\"name\":\"a\",\"type\":\"Integer\"},{\"name\":\"b\",\"type\":\"String\"}]"
},
new ResolvedScript
{
CanonicalName = "Caller",
// Two real args, but the block comment adds a spurious comma if tokenizer is not comment-aware.
Code = "CallScript(\"Target\", 42 /* ,bogus */, \"hi\");"
}
]
};
var result = _sut.Validate(config);
Assert.DoesNotContain(result.Errors, e => e.Category == ValidationCategory.ParameterMismatch);
}
// ── M2.7 review nits — stricter numeric-literal inference ───────────────
[Fact]
public void Validate_ArgumentType_UnderscoreLeadingIdentifier_NoFalsePositive()
{
// `_2` starts with an underscore — it is a C# identifier, not a numeric literal.
// IsNumericLiteral must return false → type inferred as Unknown → no mismatch.
var config = new FlattenedConfiguration
{
InstanceUniqueName = "Instance1",
Scripts =
[
new ResolvedScript
{
CanonicalName = "Target",
Code = "var x = 1;",
ParameterDefinitions = "[{\"name\":\"a\",\"type\":\"Integer\"}]"
},
new ResolvedScript
{
CanonicalName = "Caller",
Code = "CallScript(\"Target\", _2);"
}
]
};
var result = _sut.Validate(config);
Assert.DoesNotContain(result.Errors, e => e.Category == ValidationCategory.ParameterMismatch);
}
}