Custom operators in a framework

It is possible to define custom operators in a framework, but it is not possible to assign access levels to them.

As a consequence they are module internal and cannot be used outside the framework.

Each project needs to redefine the custom operators in order to use them in that project.

What is the rationale behind that?

Or is it a bug?

Are there other ways to accomplish this?

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

Operator declarations are actually public all the time, not internal. That’s itself probably a bug, but not the world-limiting one you’re concerned about.

Jordan

···

On Feb 3, 2017, at 01:18, Rien via swift-users <swift-users@swift.org> wrote:

It is possible to define custom operators in a framework, but it is not possible to assign access levels to them.

As a consequence they are module internal and cannot be used outside the framework.

Each project needs to redefine the custom operators in order to use them in that project.

What is the rationale behind that?

Or is it a bug?

Are there other ways to accomplish this?

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

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

Are you referring to the definition of the operator (infix…) or the availability of the function that defines the operator?

The functions are available, but I have to repeat the “infix…" everywhere I need them.

I.e. I have a:

infix operator &=

And when I use that from another module I get “Operator is not a known binary operator”

Once I repeat the "infix operator &=“ at the start of the file it works fine.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

···

On 03 Feb 2017, at 18:14, Jordan Rose <jordan_rose@apple.com> wrote:

Operator declarations are actually public all the time, not internal. That’s itself probably a bug, but not the world-limiting one you’re concerned about.

Jordan

On Feb 3, 2017, at 01:18, Rien via swift-users <swift-users@swift.org> wrote:

It is possible to define custom operators in a framework, but it is not possible to assign access levels to them.

As a consequence they are module internal and cannot be used outside the framework.

Each project needs to redefine the custom operators in order to use them in that project.

What is the rationale behind that?

Or is it a bug?

Are there other ways to accomplish this?

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

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

The operator itself. If you’re not seeing that behavior, that’s a bug! Do you have a small test case that reproduces it? (I guess it would take two modules regardless, so either a SwiftPM package or an Xcode project would do it.)

Jordan

···

On Feb 3, 2017, at 09:34, Rien <Rien@Balancingrock.nl> wrote:

Are you referring to the definition of the operator (infix…) or the availability of the function that defines the operator?

The functions are available, but I have to repeat the “infix…" everywhere I need them.

I.e. I have a:

infix operator &=

And when I use that from another module I get “Operator is not a known binary operator”

Once I repeat the "infix operator &=“ at the start of the file it works fine.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

On 03 Feb 2017, at 18:14, Jordan Rose <jordan_rose@apple.com> wrote:

Operator declarations are actually public all the time, not internal. That’s itself probably a bug, but not the world-limiting one you’re concerned about.

Jordan

On Feb 3, 2017, at 01:18, Rien via swift-users <swift-users@swift.org> wrote:

It is possible to define custom operators in a framework, but it is not possible to assign access levels to them.

As a consequence they are module internal and cannot be used outside the framework.

Each project needs to redefine the custom operators in order to use them in that project.

What is the rationale behind that?

Or is it a bug?

Are there other ways to accomplish this?

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

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

This is the “defining” package/module:

For the consuming package simply generate a new executable and put the following in main.swift:

import SwifterJSON

// Note: Error disappears when the line below is un-commented

// infix operator &=

var json = VJson()

json["root"] &= 4

print(json.code)

(seems I have hit a snag with github, otherwise I would create a new repo for the executable… sorry for that.)

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

···

On 03 Feb 2017, at 18:36, Jordan Rose <jordan_rose@apple.com> wrote:

The operator itself. If you’re not seeing that behavior, that’s a bug! Do you have a small test case that reproduces it? (I guess it would take two modules regardless, so either a SwiftPM package or an Xcode project would do it.)

Jordan

On Feb 3, 2017, at 09:34, Rien <Rien@Balancingrock.nl> wrote:

Are you referring to the definition of the operator (infix…) or the availability of the function that defines the operator?

The functions are available, but I have to repeat the “infix…" everywhere I need them.

I.e. I have a:

infix operator &=

And when I use that from another module I get “Operator is not a known binary operator”

Once I repeat the "infix operator &=“ at the start of the file it works fine.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

On 03 Feb 2017, at 18:14, Jordan Rose <jordan_rose@apple.com> wrote:

Operator declarations are actually public all the time, not internal. That’s itself probably a bug, but not the world-limiting one you’re concerned about.

Jordan

On Feb 3, 2017, at 01:18, Rien via swift-users <swift-users@swift.org> wrote:

It is possible to define custom operators in a framework, but it is not possible to assign access levels to them.

As a consequence they are module internal and cannot be used outside the framework.

Each project needs to redefine the custom operators in order to use them in that project.

What is the rationale behind that?

Or is it a bug?

Are there other ways to accomplish this?

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

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

Interesting. I actually see two errors:

/Users/jrose/Desktop/SwifterJSON/App/AppDelegate.swift:19:18: error: ambiguous operator declarations found for operator
    json["root"] &= 4
                 ^
<unknown>:0: note: found this matching operator declaration
<unknown>:0: note: found this matching operator declaration
/Users/jrose/Desktop/SwifterJSON/App/AppDelegate.swift:19:18: error: operator is not a known binary operator
    json["root"] &= 4
                 ^

which actually seems correct in retrospect: '&=' is already a valid operator in the 'Swift' library, and you're redefining it rather than just reusing that definition. It works if I either remove your `infix operator &=` declaration (and leave all the implementations in place), or if I change to an operator that isn't already defined. Can you file a bug at bugs.swift.org <Issues · apple/swift · GitHub; for the lousy diagnostics, at least?

Jordan

···

On Feb 3, 2017, at 11:34, Rien <Rien@Balancingrock.nl> wrote:

This is the “defining” package/module:

GitHub - Balancingrock/VJson: A framework in Swift to read/write & parse the JSON Format.

For the consuming package simply generate a new executable and put the following in main.swift:

import SwifterJSON

// Note: Error disappears when the line below is un-commented

// infix operator &=

var json = VJson()

json["root"] &= 4

print(json.code)

(seems I have hit a snag with github, otherwise I would create a new repo for the executable… sorry for that.)

Regards,
Rien

Site: http://balancingrock.nl <http://balancingrock.nl/&gt;
Blog: http://swiftrien.blogspot.com <http://swiftrien.blogspot.com/&gt;
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl <Indobet - Tempat Daftar Login Rtp Slot Gacor Indonesia;

On 03 Feb 2017, at 18:36, Jordan Rose <jordan_rose@apple.com <mailto:jordan_rose@apple.com>> wrote:

The operator itself. If you’re not seeing that behavior, that’s a bug! Do you have a small test case that reproduces it? (I guess it would take two modules regardless, so either a SwiftPM package or an Xcode project would do it.)

Jordan

On Feb 3, 2017, at 09:34, Rien <Rien@Balancingrock.nl <mailto:Rien@balancingrock.nl>> wrote:

Are you referring to the definition of the operator (infix…) or the availability of the function that defines the operator?

The functions are available, but I have to repeat the “infix…" everywhere I need them.

I.e. I have a:

infix operator &=

And when I use that from another module I get “Operator is not a known binary operator”

Once I repeat the "infix operator &=“ at the start of the file it works fine.

Regards,
Rien

Site: http://balancingrock.nl <http://balancingrock.nl/&gt;
Blog: http://swiftrien.blogspot.com <http://swiftrien.blogspot.com/&gt;
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl <Indobet - Tempat Daftar Login Rtp Slot Gacor Indonesia;

On 03 Feb 2017, at 18:14, Jordan Rose <jordan_rose@apple.com <mailto:jordan_rose@apple.com>> wrote:

Operator declarations are actually public all the time, not internal. That’s itself probably a bug, but not the world-limiting one you’re concerned about.

Jordan

On Feb 3, 2017, at 01:18, Rien via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:

It is possible to define custom operators in a framework, but it is not possible to assign access levels to them.

As a consequence they are module internal and cannot be used outside the framework.

Each project needs to redefine the custom operators in order to use them in that project.

What is the rationale behind that?

Or is it a bug?

Are there other ways to accomplish this?

Regards,
Rien

Site: http://balancingrock.nl <http://balancingrock.nl/&gt;
Blog: http://swiftrien.blogspot.com <http://swiftrien.blogspot.com/&gt;
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl <Indobet - Tempat Daftar Login Rtp Slot Gacor Indonesia;

_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users

Facepalm!

Of course!, thanks for clearing that up!

I will file a bug report for the diagnostics.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

···

On 04 Feb 2017, at 02:14, Jordan Rose <jordan_rose@apple.com> wrote:

Interesting. I actually see two errors:

/Users/jrose/Desktop/SwifterJSON/App/AppDelegate.swift:19:18: error: ambiguous operator declarations found for operator
    json["root"] &= 4
                 ^
<unknown>:0: note: found this matching operator declaration
<unknown>:0: note: found this matching operator declaration
/Users/jrose/Desktop/SwifterJSON/App/AppDelegate.swift:19:18: error: operator is not a known binary operator
    json["root"] &= 4
                 ^

which actually seems correct in retrospect: '&=' is already a valid operator in the 'Swift' library, and you're redefining it rather than just reusing that definition. It works if I either remove your `infix operator &=` declaration (and leave all the implementations in place), or if I change to an operator that isn't already defined. Can you file a bug at bugs.swift.org for the lousy diagnostics, at least?

Jordan

On Feb 3, 2017, at 11:34, Rien <Rien@Balancingrock.nl> wrote:

This is the “defining” package/module:

GitHub - Balancingrock/VJson: A framework in Swift to read/write & parse the JSON Format.

For the consuming package simply generate a new executable and put the following in main.swift:

import SwifterJSON

// Note: Error disappears when the line below is un-commented

// infix operator &=

var json = VJson()

json["root"] &= 4

print(json.code)

(seems I have hit a snag with github, otherwise I would create a new repo for the executable… sorry for that.)

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

On 03 Feb 2017, at 18:36, Jordan Rose <jordan_rose@apple.com> wrote:

The operator itself. If you’re not seeing that behavior, that’s a bug! Do you have a small test case that reproduces it? (I guess it would take two modules regardless, so either a SwiftPM package or an Xcode project would do it.)

Jordan

On Feb 3, 2017, at 09:34, Rien <Rien@Balancingrock.nl> wrote:

Are you referring to the definition of the operator (infix…) or the availability of the function that defines the operator?

The functions are available, but I have to repeat the “infix…" everywhere I need them.

I.e. I have a:

infix operator &=

And when I use that from another module I get “Operator is not a known binary operator”

Once I repeat the "infix operator &=“ at the start of the file it works fine.

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

On 03 Feb 2017, at 18:14, Jordan Rose <jordan_rose@apple.com> wrote:

Operator declarations are actually public all the time, not internal. That’s itself probably a bug, but not the world-limiting one you’re concerned about.

Jordan

On Feb 3, 2017, at 01:18, Rien via swift-users <swift-users@swift.org> wrote:

It is possible to define custom operators in a framework, but it is not possible to assign access levels to them.

As a consequence they are module internal and cannot be used outside the framework.

Each project needs to redefine the custom operators in order to use them in that project.

What is the rationale behind that?

Or is it a bug?

Are there other ways to accomplish this?

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

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