Skip to content

Screenplay generation: recover validation messages from WithMessage(_ => Constant) lambdas (SP0016) #2397

Description

@woksin

Summary

Validation-message recovery only accepts messages given as constant values directly. The very common FluentValidation shape WithMessage(_ => SomeMessages.Constant) — a lambda returning a constant — is rejected with SP0016 [Warning] A message was declared without a constant value or without a rule preceding it, and was left out. In an application that uses the message-constants pattern consistently, every validation message in the generated document is lost.

Evidence (real application)

Generating from the Ada application produced 643 SP0016 warnings, and the generated document's validate blocks carry no message "…" clauses at all. Ada's validators consistently use:

RuleFor(c => c.Name)
    .NotEmpty()
    .WithMessage(_ => AccountsMessages.Name_Required);

where AccountsMessages.Name_Required is a const string. The Screenplay grammar has first-class support for messages (not empty message "…"), so the loss is purely on the recovery side.

Two compounding notes:

  • The lambda body here is a plain member access to a const field — resolvable with the semantic model (IFieldSymbol.HasConstantValue), no evaluation needed.
  • In Ada the message classes are source generated, so recovering them also requires the host to run source generators before analysis (see the companion SP0024 issue) — but the lambda shape fails even for hand-written const classes.

Suggested fix

In the validation chain reader, when WithMessage receives a lambda whose body is a field/property reference with a compile-time constant value (or a literal), use that constant as the message. Keep SP0016 for genuinely computed messages (interpolation, method calls, localization lookups).

Environment

  • Cratis.Arc.Screenplay 20.65.0 (Analysis/Validation/ValidationChainReader.cs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions