Skip to content

Commit

Permalink
Add test for (x ? null : N) > B
Browse files Browse the repository at this point in the history
As reported in dotnet#33752, `SELECT`ing the result of a comparison between `int?` and
`int` can trigger an exception in the shaper.
  • Loading branch information
ranma42 committed May 22, 2024
1 parent e969995 commit d5d9098
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,9 @@ await AssertQueryScalar(
e => (e.BoolA ? e.NullableBoolA != e.NullableBoolB : e.BoolC) != e.BoolB
? e.BoolA
: e.NullableBoolB == e.NullableBoolC).Select(e => e.Id));
await AssertQueryScalar(
async,
ss => ss.Set<NullSemanticsEntity1>().Select(e => (e.BoolA ? e.NullableIntA : e.IntB) > e.IntC));
}

[ConditionalTheory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1745,6 +1745,17 @@ ELSE CASE
ELSE CAST(0 AS bit)
END
END = CAST(1 AS bit)
""",
//
"""
SELECT CASE
WHEN CASE
WHEN [e].[BoolA] = CAST(1 AS bit) THEN [e].[NullableIntA]
ELSE [e].[IntB]
END > [e].[IntC] THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END
FROM [Entities1] AS [e]
""");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,53 @@ public NullSemanticsQuerySqliteTest(NullSemanticsQuerySqliteFixture fixture, ITe
//Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}

public override async Task Null_semantics_conditional(bool async)
{
await base.Null_semantics_conditional(async);

AssertSql(
"""
SELECT "e"."Id"
FROM "Entities1" AS "e"
WHERE "e"."BoolA" = CASE
WHEN "e"."BoolB" THEN "e"."NullableBoolB"
ELSE "e"."NullableBoolC"
END
""",
//
"""
SELECT "e"."Id"
FROM "Entities1" AS "e"
WHERE CASE
WHEN ("e"."NullableBoolA" <> "e"."NullableBoolB" OR "e"."NullableBoolA" IS NULL OR "e"."NullableBoolB" IS NULL) AND ("e"."NullableBoolA" IS NOT NULL OR "e"."NullableBoolB" IS NOT NULL) THEN "e"."BoolB"
ELSE "e"."BoolC"
END = "e"."BoolA"
""",
//
"""
SELECT "e"."Id"
FROM "Entities1" AS "e"
WHERE CASE
WHEN CASE
WHEN "e"."BoolA" THEN ("e"."NullableBoolA" <> "e"."NullableBoolB" OR "e"."NullableBoolA" IS NULL OR "e"."NullableBoolB" IS NULL) AND ("e"."NullableBoolA" IS NOT NULL OR "e"."NullableBoolB" IS NOT NULL)
ELSE "e"."BoolC"
END <> "e"."BoolB" THEN "e"."BoolA"
ELSE ("e"."NullableBoolB" = "e"."NullableBoolC" AND "e"."NullableBoolB" IS NOT NULL AND "e"."NullableBoolC" IS NOT NULL) OR ("e"."NullableBoolB" IS NULL AND "e"."NullableBoolC" IS NULL)
END
""",
//
"""
SELECT CASE
WHEN CASE
WHEN "e"."BoolA" THEN "e"."NullableIntA"
ELSE "e"."IntB"
END > "e"."IntC" THEN 1
ELSE 0
END
FROM "Entities1" AS "e"
""");
}

public override async Task Null_semantics_contains_non_nullable_item_with_non_nullable_subquery(bool async)
{
await base.Null_semantics_contains_non_nullable_item_with_non_nullable_subquery(async);
Expand Down

0 comments on commit d5d9098

Please sign in to comment.