Re: [swift-users] Cannot pass immutable value as inout argument

2018-01-16 Thread Jordan Rose via swift-users
Oh no, you're right, I'm sorry. You can only do that with arrays at the moment. 
We do have a bug for this already.

Jordan


> On Jan 16, 2018, at 16:37, Roderick Mann  wrote:
> 
> Xcode can't properly parse the C header to show me the Swift signature, but 
> if I try calling it like this:
> 
>let p = lgs_notify_params_t(notify: lgs_notify_did_enter_background)
>lgs_notify(self.ctx, p)
> 
> I get this error:
> 
> Cannot convert value of type 'lgs_notify_params_t' to expected argument type 
> 'UnsafePointer!'
> 
> 
>> On Jan 16, 2018, at 13:22 , Jordan Rose  wrote:
>> 
>> You can do this if you don't write '&', which incorporates the caveat that 
>> you're not passing a stable address. But please file a bug anyway, because 
>> the diagnostic should tell you that!
>> 
>> Jordan
>> 
>> 
>>> On Jan 16, 2018, at 13:10, Rick Mann via swift-users 
>>>  wrote:
>>> 
>>> Is it not possible for Swift to treat C API const pointers as something 
>>> that can take let arguments?
>>> 
>>> 
>>> LGS_EXPORT bool lgs_notify(struct lgs_context_t* ctx, const 
>>> lgs_notify_params_t* params);
>>> .
>>> .
>>> .
>>> let p = lgs_notify_params_t(...)
>>> lgs_notify(self.ctx, )
>>>^Cannot pass immutable value as inout argument: 'p' is a 
>>> 'let' constant
>>> 
>>> 
>>> Why isn't the "const" in the C declaration enough to let Swift know it's 
>>> const and just allow it to be a let?
>>> 
>>> -- 
>>> Rick Mann
>>> rm...@latencyzero.com
>>> 
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-users
>> 
> 
> 
> -- 
> Rick Mann
> rm...@latencyzero.com 
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Cannot pass immutable value as inout argument

2018-01-16 Thread Roderick Mann via swift-users
Xcode can't properly parse the C header to show me the Swift signature, but if 
I try calling it like this:

let p = lgs_notify_params_t(notify: lgs_notify_did_enter_background)
lgs_notify(self.ctx, p)

I get this error:

Cannot convert value of type 'lgs_notify_params_t' to expected argument type 
'UnsafePointer!'


> On Jan 16, 2018, at 13:22 , Jordan Rose  wrote:
> 
> You can do this if you don't write '&', which incorporates the caveat that 
> you're not passing a stable address. But please file a bug anyway, because 
> the diagnostic should tell you that!
> 
> Jordan
> 
> 
>> On Jan 16, 2018, at 13:10, Rick Mann via swift-users  
>> wrote:
>> 
>> Is it not possible for Swift to treat C API const pointers as something that 
>> can take let arguments?
>> 
>> 
>> LGS_EXPORT bool lgs_notify(struct lgs_context_t* ctx, const 
>> lgs_notify_params_t* params);
>> .
>> .
>> .
>> let p = lgs_notify_params_t(...)
>> lgs_notify(self.ctx, )
>> ^Cannot pass immutable value as inout argument: 'p' is a 
>> 'let' constant
>> 
>> 
>> Why isn't the "const" in the C declaration enough to let Swift know it's 
>> const and just allow it to be a let?
>> 
>> -- 
>> Rick Mann
>> rm...@latencyzero.com
>> 
>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
> 


-- 
Rick Mann
rm...@latencyzero.com


___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Cannot pass immutable value as inout argument

2018-01-16 Thread Jordan Rose via swift-users
You can do this if you don't write '&', which incorporates the caveat that 
you're not passing a stable address. But please file a bug anyway, because the 
diagnostic should tell you that!

Jordan


> On Jan 16, 2018, at 13:10, Rick Mann via swift-users  
> wrote:
> 
> Is it not possible for Swift to treat C API const pointers as something that 
> can take let arguments?
> 
> 
> LGS_EXPORT bool lgs_notify(struct lgs_context_t* ctx, const 
> lgs_notify_params_t* params);
> .
> .
> .
> let p = lgs_notify_params_t(...)
> lgs_notify(self.ctx, )
> ^Cannot pass immutable value as inout argument: 'p' is a 
> 'let' constant
> 
> 
> Why isn't the "const" in the C declaration enough to let Swift know it's 
> const and just allow it to be a let?
> 
> -- 
> Rick Mann
> rm...@latencyzero.com
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Cannot pass immutable value as inout argument

2018-01-16 Thread Rick Mann via swift-users
Is it not possible for Swift to treat C API const pointers as something that 
can take let arguments?


LGS_EXPORT bool lgs_notify(struct lgs_context_t* ctx, const 
lgs_notify_params_t* params);
.
.
.
let p = lgs_notify_params_t(...)
lgs_notify(self.ctx, )
 ^Cannot pass immutable value as inout argument: 'p' is a 
'let' constant


Why isn't the "const" in the C declaration enough to let Swift know it's const 
and just allow it to be a let?

-- 
Rick Mann
rm...@latencyzero.com


___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] TWISt-shout Newsletter 2018-01-15

2018-01-16 Thread Jordan Rose via swift-users
For posterity, I object to the phrasing "Swift arrays are not thread safe". The 
problem was that "globals are not (automatically) thread-safe". Arrays are no 
less thread safe than class references here.

Jordan


> On Jan 15, 2018, at 13:09, Kenny Leung via swift-users 
>  wrote:
> 
> Hi All.
> 
> Here is your TWISt-shout Newsletter for the week of 2018-01-08 to 2018-01-14
> 
> https://github.com/pepperdog/TWISt-shout/blob/master/2018/TWISt-shout-2018-01-15.md
>  
> 
> 
> Enjoy!
> 
> -Kenny
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] KeyPaths and PartialKeyPaths - when can you leave out the class?

2018-01-16 Thread Karl Wagner via swift-users
+1

An example I ran in to today:

func dumpKeys(of object: T, _ keypaths: PartialKeyPath...) {
  for kp in keypaths {
print("-", "\(kp): \(object[keyPath: kp])")
  }
}

Then in LLDB, I want to be able to write:

dumpKeys(of: context, \.invalidateEverything, \.invalidateDataSourceCounts)

But the PartialKeyPath expressions are considered ambiguous :(

- Karl

> On 12. Jan 2018, at 02:20, Kenny Leung via swift-users 
>  wrote:
> 
> Filed as https://bugs.swift.org/browse/SR-6740 
> 
> 
> -Kenny
> 
> 
>> On Jan 11, 2018, at 3:12 PM, Jordan Rose > > wrote:
>> 
>> I'm not sure whether it was supposed to be supported or not, but either way 
>> it's a reasonable feature request. Please file at bugs.swift.org 
>> .
>> 
>> Jordan
>> 
>> 
>>> On Jan 11, 2018, at 14:41, Kenny Leung via swift-users 
>>> > wrote:
>>> 
>>> Hi All.
>>> 
>>> I’d like to be lazy and leave out the classname on a key path whenever 
>>> possible. I thought that if PartialKeyPath was specified as the argument 
>>> type, that meant the compiler should be able to figure out what the class 
>>> is, but this does not seem to be the case.
>>> 
>>> Here’s an example that works.
>>> 
>>> class ThePath {
>>> var isWinding:Bool?
>>> }
>>> 
>>> func walk(aPath:T, forKey:PartialKeyPath) {
>>> }
>>> 
>>> func walkThePath(aPath:ThePath, forKey:PartialKeyPath) {
>>> }
>>> 
>>> func test() {
>>> let path = ThePath()
>>> walkThePath(aPath:path, forKey:\ThePath.isWinding)
>>> walk(aPath:path, forKey:\ThePath.isWinding)
>>> }
>>> 
>>> If you do this then it complains:
>>> 
>>> func test() {
>>> let path = ThePath()
>>> walkThePath(aPath:path, forKey:\.isWinding) // Expression type '()' is 
>>> ambiguous without more context
>>> walk(aPath:path, forKey:\.isWinding)// Type of expression is 
>>> ambiguous without more context
>>> }
>>> 
>>> Should I be able to do this?
>>> 
>>> Thanks!
>>> 
>>> -Kenny
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org 
>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>> 
>> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users