Skip to content

Misleading error message for ?? throw. #24891

Open
@lrhn

Description

@lrhn

The expression

  x ?? throw new ArgumentError("NOooooooooooo....!");

gives the error message:

Error: Expected an expression, but got 'throw'.                                 
  x ?? throw new ArgumentError("NOooooooooooo....!");                           
       ^^^^^                                                                    
Error: Compilation failed.                                                      

This is misleading since throw is an expression. A more correct error message would be:

"throw" is not allowed at this point. Try wrapping the "throw" expression in parentheses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestlegacy-area-front-endLegacy: Use area-dart-model instead.type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions