Re: [swift-users] Weird protocol behaviour.

2016-12-22 Thread Guillaume Lessard via swift-users
The function foo(x: A){} requires a type which conforms to protocol P.

An existential of protocol P does not actually conform to protocol P.
It’s always been a limitation in Swift: https://bugs.swift.org/browse/SR-55

If the function’s signature were foo(x: P){}, it would work.


Howard’s example swaps the protocol P for a concrete type (P1), which is what 
makes it work.

Cheers,
Guillaume Lessard

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


Re: [swift-users] Weird protocol behaviour.

2016-12-22 Thread Howard Lovatt via swift-users
The following variation works:

protocol P {}


class P1:P {}


class X:P1 {}


func foo(_ x:A) {}


func bar() {

//let x = X() // this compiles

let x = X() as P1 // this does not compile. Why?

foo(x)

}

Which adds credence to the bug theory.

Note two changes: 1. two levels of inheritance and 2. change to classes. If
you do two levels using protocols it doesn't work if you use either classes
or structs.


  -- Howard.

On 23 December 2016 at 07:29, Kevin Nattinger  wrote:

> I recall seeing a request on the -evolution list for something like `T :=
> X` to indicate it could be X itself or anything inheriting / implementing
> it, so it’s certainly known behavior, if not desired. IMO it’s a bug and
> `:` should be fixed to include the root type, whether or not that requires
> a discussion on -evolution.
>
> On Dec 22, 2016, at 2:17 PM, Howard Lovatt via swift-users <
> swift-users@swift.org> wrote:
>
> I suspect a compiler bug since A is a P. The equivalent in Java works:
>
> interface P {}
> class X implements P {}
>
>
>  void foo(A x) {}
>
>
> void bar() {
> final P x = new X();
> foo(x);
> }
>
> -- Howard.
>
> On 23 Dec 2016, at 3:19 am, Rien via swift-users 
> wrote:
>
> IMO the error message says it all:
>
> Playground execution failed: error: MyPlayground8.playground:9:5: error:
> cannot invoke 'foo' with an argument list of type '(P)'
>foo(x)
>^
>
> MyPlayground8.playground:9:5: note: expected an argument list of type '(A)'
>foo(x)
>^
>
> I.e. you are passing in a protocol while the function is specified for a
> type.
> Said other way: On which data do you expect the protocol to operate?
>
> Regards,
> Rien
>
> Site: http://balancingrock.nl
> Blog: http://swiftrien.blogspot.com
> Github: http://github.com/Swiftrien
> Project: http://swiftfire.nl
>
>
>
>
> On 22 Dec 2016, at 17:05, Mikhail Seriukov via swift-users <
> swift-users@swift.org> wrote:
>
>
> Hello community! I' wondering if somebody can explain this to me.
>
> Please take look at the snippet.
>
>
> protocol P {}
>
> struct X:P {}
>
>
> func foo(_ x:A) {}
>
>
> func bar() {
>
>//let x = X() // this compiles
>
>let x = X() as P // this does not compile. Why?
>
>foo(x)
>
> }
>
>
> I expect the both cases to work though. But only first works? And I do not
> understand why.
>
> My coworkers said that it is a compiler bug, but I'm not shure it is.
>
> Thanks for the help.
>
> ___
>
> 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
>
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Possible bug in Swift REPL autocompletion?

2016-12-22 Thread Eugenio Baglieri via swift-users
Good evening, i was  playing with swift REPL. I imported Darwin and using c 
functions. I noted that autocompletion is unusable if the last character is a 
parenthesis “(“. 
The autocompletion seems to not get account of the already written function 
name, and after parenthesis shows as possible completion an infinite list with 
all the parameters of all loaded libraries. 

Is this an issue that could be opened? You can reproduce this following these 
steps:

- launch swift from terminal
- write “import Darwin” on Mac, or “import Glibc” on Ubuntu
- digit “fop” and press tab, you’ll get autocompleted with “fopen(“ press tab 
again

— 
Eugenio B.


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


[swift-users] How do I use Xcode for a C library wrapped in Swift

2016-12-22 Thread Dave Yost via swift-users
I just posted this on StackOverflow 
.
 Insights most welcome.

I'm trying to create an Xcode workspace that contains projects that make:

A bird dynamic library built from C source
A Cbird Swift module that wraps bird in raw Swift
A Bird Swift module that imports Cbird and wraps it in swifty Swift
A birdchirp Swift Command Line Tool that imports Bird
All of these must have an OS X Unit Testing Bundle.

I've tried various ways with various versions of Swift 3.x and snapshots to do 
this starting from Project.swift files and using swift package 
generate-xcodeproj. All of these attempts have resulted in Xcode setups that 
have various problems:

having to do a swift build first and then rooting an Xcode project in a 
directory deep within the .build directory (created by swift build) or within 
the (apparently now defunct) Packages directory
having to refer to other projects via github addresses
trouble with unit test bundles not finding Cbird
Selecting Cbird in an import Cbird source line and doing Jump to Definition 
fails to show the Swift source for Cbird.
The birdchirp project cheats and refers to Bird source files directly instead 
of depending on the Bird framework.
Extra credit:

Package.swift files that work with relative references to the other projects, 
while still allowing the projects to be mirrors of GitHub projects

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


Re: [swift-users] Weird protocol behaviour.

2016-12-22 Thread Kevin Nattinger via swift-users
I recall seeing a request on the -evolution list for something like `T := X` to 
indicate it could be X itself or anything inheriting / implementing it, so it’s 
certainly known behavior, if not desired. IMO it’s a bug and `:` should be 
fixed to include the root type, whether or not that requires a discussion on 
-evolution.

> On Dec 22, 2016, at 2:17 PM, Howard Lovatt via swift-users 
>  wrote:
> 
> I suspect a compiler bug since A is a P. The equivalent in Java works:
> 
> interface P {}
> class X implements P {}
>  
>  void foo(A x) {}
>  
> void bar() {
> final P x = new X();
> foo(x);
> }
> 
> -- Howard. 
> 
> On 23 Dec 2016, at 3:19 am, Rien via swift-users  > wrote:
> 
>> IMO the error message says it all:
>> 
>> Playground execution failed: error: MyPlayground8.playground:9:5: error: 
>> cannot invoke 'foo' with an argument list of type '(P)'
>>foo(x)
>>^
>> 
>> MyPlayground8.playground:9:5: note: expected an argument list of type '(A)'
>>foo(x)
>>^
>> 
>> I.e. you are passing in a protocol while the function is specified for a 
>> type.
>> Said other way: On which data do you expect the protocol to operate?
>> 
>> Regards,
>> Rien
>> 
>> Site: http://balancingrock.nl 
>> Blog: http://swiftrien.blogspot.com 
>> Github: http://github.com/Swiftrien 
>> Project: http://swiftfire.nl 
>> 
>> 
>> 
>> 
>>> On 22 Dec 2016, at 17:05, Mikhail Seriukov via swift-users 
>>> > wrote:
>>> 
>>> Hello community! I' wondering if somebody can explain this to me.
>>> Please take look at the snippet.
>>> 
>>> protocol P {}
>>> struct X:P {}
>>> 
>>> func foo(_ x:A) {}
>>> 
>>> func bar() {
>>>//let x = X() // this compiles
>>>let x = X() as P // this does not compile. Why?
>>>foo(x)
>>> }
>>> 
>>> I expect the both cases to work though. But only first works? And I do not 
>>> understand why.
>>> My coworkers said that it is a compiler bug, but I'm not shure it is.
>>> Thanks for the help.
>>> ___
>>> 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

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


Re: [swift-users] Bls: Bls: module (de)-initialization

2016-12-22 Thread Glenn L. Austin via swift-users
> On Dec 21, 2016, at 7:29 PM, Mr Bee via swift-users  
> wrote:
> 
> Sorry for not being clear. My english isn't very good either.
> 
> What I meant was static module linking (loading and unloading) for Swift 
> modules. Also with initialization and deinitialization for Swift modules.
> 
> It's alright then. I just want to make sure. I'm a Pascal/Delphi programmer 
> and sometimes I rely on such features in my applications. As a new and 
> considered as modern programming language, I thought Swift would provide more 
> advance features than Pascal/Delphi does.
> 
> Thank you.
>  
> 
> –Mr Bee

Many of us also depend upon dynamic linking, but the runtime for Swift (and 
Objective-C) is far more complex than just loading new code.

When loading code, there are things that "just happen" -- such as class 
extensions -- that need to be unlinked when the dynamic library is unloaded. 
For one thing if you had objects created while the class extension was 
available, those objects would have to be "re-written" to not use the class 
extension any more. If the extension allocated additional memory, that memory 
would be orphaned.

Dynamic languages are far more complex than static languages like Pascal and 
Delphi...

-- 
Glenn L. Austin, Computer Wizard and Race Car Driver <><


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