Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listener type needs to be parameterized in service object type #615

Closed
jclark opened this issue Sep 30, 2020 · 4 comments
Closed

Listener type needs to be parameterized in service object type #615

jclark opened this issue Sep 30, 2020 · 4 comments
Assignees
Labels
Area/Lang Relates to the Ballerina language specification Type/Improvement Enhancement to language design

Comments

@jclark
Copy link
Collaborator

jclark commented Sep 30, 2020

In order to make #611 useable, the Listener abstract object type needs to become a parameterized type Listener<S>, where S is the service object type.

If some listener, e.g. FooListener defines an attach method whose first argument is a FooService, which defines some remote methods, then FooListener will not be a subtype of Listener as currently defined (because of parameter type contravariance). Instead it will be a subtype of Listener<FooService>.

@jclark jclark self-assigned this Sep 30, 2020
@jclark jclark added this to the Swan Lake November preview milestone Sep 30, 2020
@jclark jclark added Type/Improvement Enhancement to language design Area/Lang Relates to the Ballerina language specification labels Sep 30, 2020
@jclark
Copy link
Collaborator Author

jclark commented Oct 1, 2020

In order to write the type for Listener in lang.object, we need a way to express that an object type has a type parameter, e.g. by extending @typeParam. We also need this for #434.

@jclark
Copy link
Collaborator Author

jclark commented Oct 12, 2020

It's not going to work to use @typeParam to describe Listener in lang.object, because there is no way for the user to reference this type (e.g. using Listener<T>). I think the best we can do is to define the service argument to attach as never i.e. object:Listener is Listener<never>. This ensures that the abstract type Listener<T> is a subtype of object:Listener for any T. We can do better probably when we do #609 or obviously if we add generic types.

The reason we need Listener in lang.object is so that all Listeners can belong to the same distinct type. So another possibility, perhaps less confusing, is just to define object:Listener as distinct object {}. Another possibility would be to not make Listener distinct (is there any need for it to be distinct?) and not define it in lang.object.

@jclark
Copy link
Collaborator Author

jclark commented Oct 14, 2020

I chatted with @hasithaa and our conclusion was that the easiest solution was to make Listener like Iterator i.e.

  • not a distinct type
  • no declaration in lang.object
  • purely spec-internal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Lang Relates to the Ballerina language specification Type/Improvement Enhancement to language design
Projects
None yet
Development

No branches or pull requests

1 participant