i want line number have called subscript debugging purposes (like index out of range , on):
/* 1*/ struct collection { /* 2*/ // works flawlessly /* 3*/ func getelement(index: int, line: uint = #line) -> double { /* 4*/ print(line) // 16 /* 5*/ return 0.0 /* 6*/ } /* 7*/ /* 8*/ // error: default argument permitted non-curried function parameter /* 9*/ subscript(index: int, line: uint = #line) -> double { /*10*/ print(line) // should print 17 /*11*/ return 0.0 /*12*/ } /*13*/ } /*14*/ /*15*/ let c = collection() /*16*/ c.getelement(1) /*17*/ c[1]
as can see subscript version not work.
is there workaround limitation?
i'm surprised isn't possible! tested myself (with swift 2.2), , can confirm happens.
there seems no workaround this. may or may not bug. if think error unintentional, encourage file bug @ https://bugs.swift.org.
edit: @martinr correctly pointed out documentation in comments section:
subscripts can take number of input parameters, , these input parameters can of type. subscripts can return type. subscripts can use variable parameters , variadic parameters, cannot use in-out parameters or provide default parameter values.
this is intentional behavior.