Skip to content

Incorrect compilation error when adding optional arguments to multiple function arguments #3087

Closed as not planned
@ubeing

Description

@ubeing

What happened?

"Expected to find ')'."

Steps to reproduce problem

Additional info

VScode Copilot repeated error correction is invalid, Cursor repeated error correction is invalid.

Machine

MacBook Pro 15"
Operating system:
macOS
Version:
15.1

Your code

What code was in the editor, if any, when the failure occurred? You
can paste it in below:

    String userInfo(String name,  {String gender = 'unknown'}, [int age = 0]) {
        return 'Hi, $name, gender: $gender, age: $age';
    }

DartPad's output

Did DartPad print anything to the console pane? If so, paste it below:

parameters.dart:1:58: Error: Expected ')' before this.
String userInfo(String name,  {String gender = 'unknown'}, [int age = 0]) {
                                                         ^
parameters.dart:2:45: Error: Undefined name 'age'.
  return 'Hi, $name, gender: $gender, age: $age';

If you were running Flutter code, you can also paste an image of the
Flutter output directly into this bug report.

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