swiftlang/swift

[SR-11885] Allow operator functions to have extra arguments with default values

Open

#54,301 opened on Dec 2, 2019

View on GitHub
 (7 comments) (3 reactions) (0 assignees)Swift (10,719 forks)batch import
compilerdeclarationsfeaturefuncgood first issueimprovementoperatorsswift evolution proposal needed

Repository metrics

Stars
 (69,989 stars)
PR merge metrics
 (Avg merge 8d 17h) (510 merged PRs in 30d)

Description

Previous ID SR-11885
Radar rdar://problem/57711758
Original Reporter @CodaFi
Type New Feature
Votes 1
Component/s Compiler
Labels New Feature, LanguageFeatureRequest, StarterBug, StarterProposal
Assignee mininny (JIRA)
Priority Medium

md5: 210d53f6b32e8240f74a2e7677a3c698

Issue Description:

It might make sense to allow operators to have default arguments, and for those defaults to not count towards the overall arity of the operator. For example, a custom operator `<-` could have `#line` and `#file` defaults in a debug configuration. It could then check some extra invariants in a particular configuration, or do some error reporting, etc.

infix operator <-
// Still infix because it has 2 formal arguments and 1 default
public func <- (lhs: T, rhs :T, file: StaticString = #file) -> U { /**/ }

This change requires an evolution proposal.

Contributor guide