Skip to content

ambiguous behaviour: optional parameter after varargs of the same type has unclear behaviour #1556

Description

@Luyten-Orion

Optional parameter T after a varargs T doesn't have clear semantics in how it's defined.

Example

proc test(a: varargs[string], b = "") =
  echo "a=", a
  echo "b=", b

test("hello")
test("hello", "world", "!")

Actual Output

a=["hello"]
b=
a=["hello", "world"]
b=!

Expected Output

Not too sure...

Possible Solution

In my opinion, emitting a warning that says something along the lines "optional T after varargs T will cause the last argument of type T to be passed to the optional parameter!"

Additional Information

References

Activity

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

    compiler/semRelated to semantic-analysis system of the compilerlanguage-designLanguage design syntax, semantics, types, statics and dynamics.

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions