Skip to content

Commit 5555ee6

Browse files
committed
New alternatives considered: Initializer syntax.
1 parent d8f4cb3 commit 5555ee6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

proposals/NNNN-lifetime-dependency.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,27 @@ Removing a lifetime dependency constraint only affects existing source code in t
793793

794794
## Alternatives considered
795795

796+
### Initializer syntax: result vs. inout syntax
797+
798+
The programming model for initializers is that they return `self` (with an implicit return statement):
799+
800+
`init(arg: ArgType) -> dependsOn(arg) Self`
801+
802+
But some people have criticized this syntax. They prefer to think of an initializer as mutating `self`, which would be
803+
spelled:
804+
805+
`dependsOn(self: arg) init(arg: ArgType)`
806+
807+
We could adopt either or both of these options.
808+
809+
In a future with component lifetimes the syntax would look like either:
810+
811+
`init(arg1: Element, arg2: Element) -> dependsOn(a: arg1, b: arg2) Self {...}`
812+
813+
or
814+
815+
`dependsOn(self.a: arg1, self.b: arg2) init(arg1: Element, arg2: Element) -> Self {...}`
816+
796817
### Different Position
797818

798819
We propose above putting the annotation on the return value, which we believe matches the intuition that the method or property is producing this lifetime dependence alongside the returned value.

0 commit comments

Comments
 (0)