Skip to content

Application to named parameters #12

@Andersmholmgren

Description

@Andersmholmgren

Currently named parameters with default values often become useless as explicitly passing null stops the default occurring.

For example

foo({String blah: 'blah'});

bar({String blah}) => foo(blah: blah);

If blah is null into bar then it will pass that to foo and the default value not used

So in practice you end up needing to do

foo({String blah}) {
  if (blah == null)  blah = 'blah'
}

This seems to happen so often as to almost render defaults on named parameters fairly useless.

Does this proposal provide any help for this case?

Does it need extra sugar? Dare I suggest

foo(blah ?: possiblyNullValue);

where the semantics are if possiblyNullValue is null then don't set the named parameter blah to method foo (leave it to default)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions