Skip to content

Commit 8e1e491

Browse files
committed
fix emission of record access functions in Elm compiler
1 parent d420fce commit 8e1e491

5 files changed

Lines changed: 502 additions & 1 deletion

File tree

implement/Pine.Core.Tests/Elm/ElmCompilerInDotnet/ApplicationTests/ElmParserExpressionTests.cs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,4 +507,89 @@ public void Expression_nested_list_four_by_ten()
507507
LoopIterationCount: 0
508508
""");
509509
}
510+
511+
/// <summary>
512+
/// Parses the bare expression <c>"1 + 2"</c> via the real
513+
/// <c>Elm.Parser.Expression.expression</c>. This is the narrowest
514+
/// reproduction of the open compile-to-PineVM defect tracked in
515+
/// <c>ElmSyntaxInterpreter-language-service-gaps.md</c>: it fails
516+
/// with the same
517+
/// <c>Failed to parse expression from value: Unexpected number of
518+
/// items in list: Not 2 but 0 — expressionValue is string ''</c>
519+
/// symptom observed through <c>addWorkspaceFile</c> and through the
520+
/// file-level reproductions in
521+
/// <see cref="ElmParserFileTests.File_matches_language_service_scenario_ModuleA"/>
522+
/// and
523+
/// <see cref="ElmParserFileTests.File_matches_language_service_scenario_ModuleB"/>,
524+
/// but without needing an entire module header around it.
525+
/// <para>
526+
/// The passing sibling tests
527+
/// <see cref="Expression_int_literal"/>,
528+
/// <see cref="Expression_application_with_various_argument_kinds"/>,
529+
/// and the list-expression cases prove that the expression
530+
/// parser's literal, application, lambda, and list code paths all
531+
/// compile to IR correctly. What this test adds is the
532+
/// precedence-climbing path — specifically <c>precedence6Add</c> in
533+
/// <c>elm-syntax/src/Elm/Parser/Expression.elm</c> and the
534+
/// surrounding combinators — which the previous passing tests
535+
/// never reach because their inputs contain no infix operator.
536+
/// </para>
537+
/// </summary>
538+
[Fact]
539+
public void Expression_int_plus_int()
540+
{
541+
var (value, _) =
542+
CoreLibraryModule.CoreLibraryTestHelper.ApplyAndProfileUnary(
543+
GetTestFunction("parseExpression"),
544+
ElmString("1 + 2"),
545+
s_vm);
546+
547+
ElmValue.RenderAsElmExpression(value).expressionString
548+
.Should().Be(
549+
"""Ok (OperatorApplication "+" Left (Node { end = { column = 2, row = 1 }, start = { column = 1, row = 1 } } (Integer 1)) (Node { end = { column = 6, row = 1 }, start = { column = 5, row = 1 } } (Integer 2)))""");
550+
}
551+
552+
/// <summary>
553+
/// Companion to <see cref="Expression_int_plus_int"/>: probes whether
554+
/// the compile-to-PineVM defect also reproduces on the <c>|&gt;</c>
555+
/// operator (another <c>infixLeft</c>). If this fails identically to
556+
/// <see cref="Expression_int_plus_int"/> the defect is not specific
557+
/// to <c>precedence6Add</c> or to <c>Basics.add</c>, and the shared
558+
/// <c>infixLeft</c> / precedence-climbing machinery is the suspect;
559+
/// if it passes, something distinguishes <c>+</c> from <c>|&gt;</c>.
560+
/// </summary>
561+
[Fact]
562+
public void Expression_value_pipeRight_value()
563+
{
564+
var (value, _) =
565+
CoreLibraryModule.CoreLibraryTestHelper.ApplyAndProfileUnary(
566+
GetTestFunction("parseExpression"),
567+
ElmString("a |> b"),
568+
s_vm);
569+
570+
ElmValue.RenderAsElmExpression(value).expressionString
571+
.Should().Be(
572+
"""Ok (OperatorApplication "|>" Left (Node { end = { column = 2, row = 1 }, start = { column = 1, row = 1 } } (FunctionOrValue [] "a")) (Node { end = { column = 7, row = 1 }, start = { column = 6, row = 1 } } (FunctionOrValue [] "b")))""");
573+
}
574+
575+
/// <summary>
576+
/// Companion probe: <c>==</c> is <c>infixNonAssociative 4 "=="</c>,
577+
/// a sibling of <c>infixLeft</c> sharing the same
578+
/// <c>extendedSubExpressionOptimisticLayout</c> machinery. Used to
579+
/// discriminate between <c>infixLeft</c>-only defects and
580+
/// defects in the shared precedence-climbing code path.
581+
/// </summary>
582+
[Fact]
583+
public void Expression_value_eq_value()
584+
{
585+
var (value, _) =
586+
CoreLibraryModule.CoreLibraryTestHelper.ApplyAndProfileUnary(
587+
GetTestFunction("parseExpression"),
588+
ElmString("a == b"),
589+
s_vm);
590+
591+
ElmValue.RenderAsElmExpression(value).expressionString
592+
.Should().Be(
593+
"""Ok (OperatorApplication "==" Non (Node { end = { column = 2, row = 1 }, start = { column = 1, row = 1 } } (FunctionOrValue [] "a")) (Node { end = { column = 7, row = 1 }, start = { column = 6, row = 1 } } (FunctionOrValue [] "b")))""");
594+
}
510595
}

0 commit comments

Comments
 (0)