Skip to content

CMTK0003 misses assertion failures hidden in nested task combinators #165

Closed

Description

@CaffeinatedCoder

Problem

The new CMTK0003 task-combinator handling only considers the outer combinator's failure behavior. An awaited Task.WhenAll or Task.Run can carry a nested assertion task as a successful value rather than observe its failure, but the analyzer reports nothing.

Reproduced at release tip 9878a6cb7500dbf7d3e1a199c3b9446d7e5cc278, using the real built analyzer and Testing assemblies with Roslyn Compilation.WithAnalyzers. The snippets have no compiler errors:

public static async Task Check(Task<Option<int>> first, Task<Option<int>> second)
{
    await Task.WhenAll(Task.WhenAny(first.ShouldBeNone(), second.ShouldBeNone()));
    await Task.Run(() => Task.WhenAny(first.ShouldBeNone(), second.ShouldBeNone()));
}

Neither line produces CMTK0003. The same loss is silent through .Wait() and an implicit plain-Task return:

Task.WhenAll(Task.WhenAny(first.ShouldBeNone(), second.ShouldBeNone())).Wait();
Func<Task> check = () => Task.WhenAll(Task.WhenAny(first.ShouldBeNone(), second.ShouldBeNone()));

A runtime check with Some(42) confirmed that both awaited outer combinators complete successfully while the Task returned as their value is faulted with TypeKitAssertionException. Thus a test can contain await on every statement and still pass when all the assertions fail.

Cause

IgnoredOutcomeAnalyzer.DroppedAssertion suppresses the check whenever awaited and Tasks.PassesOnFailure for the outer method is true. WhenAll and Run pass on failures of the tasks they await, but an inner WhenAny never faults; it hands on the assertion's task as its value. The current check does not preserve that distinction through nesting.

Expected

Preserve failure observation through nested combinators rather than treating an awaited outer WhenAll/Run as observing all descendant assertions. Add compositions to DroppedTaskShapes: a non-faulting inner combinator under WhenAll/Run, through await/Wait/plain-Task conversion, versus a genuinely observed assertion and await await Task.WhenAny(...) as a silent control.

Direct dropped WhenAll and directly awaited WhenAny are now correctly diagnosed, and the original #152 wrapper/branch examples are fixed. This is a further composition gap in the new reach, found in the second pre-release review. Decide and fix before the tag under decision 119.

Activity

  1. added this to the 2.3.0 milestone on Oct 29, 2026
  2. added
    bug
    silent
    severity/medium
    package/analyzers
    package/testing
    area/option-result
    on Oct 29, 2026
  3. CaffeinatedCoder commented on Oct 29, 2026

    @CaffeinatedCoder
    OwnerAuthor

    Fixed in #172 (into release/2.3.0, commit f636a06). HandsOn now returns how deep the statement holds the failure: 0 where the task faults with it (WhenAll, Run), +1 per task that completes with it as a value (WhenAny, WhenEach, an async lambda that returns it), −1 per await that unwraps one. An awaited, waited-for or plain-Task combinator observes only depth 0. So await Task.WhenAll(Task.WhenAny(…)), await Task.Run(() => Task.WhenAny(…)), their .Wait() and Func<Task> forms report at any depth; await await Task.WhenAny(…) stays silent. Task.WaitAll(Task.WhenAny(…)) was already reported once, at the WhenAny's conversion. DroppedTaskShapes gained the nesting matrix (each combinator inside each other, three and four deep, arrays, Selects, async lambdas awaiting once/twice/three times), assertion-only: tasks of Result keep 2.2.0's rule. Not reached, silent: several awaits at the statement root (await await Task.WhenAny(Task.WhenAny(…))).

  4. CaffeinatedCoder commented on Oct 29, 2026

    @CaffeinatedCoder
    OwnerAuthor

    Fixed by #172, merged into release/2.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/option-resultbugpackage/analyzerspackage/testingseverity/mediumsilent

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions