Skip to content

Support default values for function arguments #34

@harlanhaskins

Description

@harlanhaskins

Default arguments should just be AST nodes we can copy at call time if they're not provided.
They should be scoped to the caller of the function, so special expressions like #file are populated with the caller's values, unlike the Python behavior where defaults are globally scoped.

For example:

func fatalError(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {}

// This call here...
fatalError("Index out of bounds")

// ...desugars in Sema as:
fatalError("Index out of bounds", file: #file, function: #function, line: #line)

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