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

Clarification on propagating CET of the conditional expression to the then else expressions #1267

Open
rdulmina opened this issue Oct 11, 2023 · 2 comments
Assignees
Labels
Area/Lang Relates to the Ballerina language specification spec/undefined Spec does not define some behavour Type/Improvement Enhancement to language design

Comments

@rdulmina
Copy link
Contributor

Description:
Currently in the jballerina implementation, the following sample is allowed

    float r = true? 1 : 1;

But the spec doesn't mention propagating the CET of the conditional expression to the then else expressions. Should we add this to the spec or change the implementation?

@rdulmina rdulmina added the spec/undefined Spec does not define some behavour label Oct 11, 2023
@rdulmina
Copy link
Contributor Author

rdulmina commented Oct 11, 2023

It seems like we have more expressions similar to this that the spec doesn't mention propagating the CET to the sub-expressions.

int a = checkpanic dependentlyTypedFunc();

float b = let int x = 5 in x * 2;

float|error c = trap 2;

future<int> b =  start dependentlyTypedFunc(); // Currenly gives error due to other reason

These are currently allowed in the implementation

@jclark
Copy link
Collaborator

jclark commented Oct 18, 2023

Generally the spec only says anything about propagating the conditionally expected type when it's not obvious how it should be propagated. When the spec says nothing about how to propagate the contextually expected type, you should do the obvious thing, rather than do nothing. Same goes for static typing rules. In an ideal world it would spell all this out, but realistically that isn't going to happen any time soon.

In these cases, I would say it's obvious what to do...

@anupama-pathirage anupama-pathirage added Type/Improvement Enhancement to language design Area/Lang Relates to the Ballerina language specification labels Nov 20, 2024
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 spec/undefined Spec does not define some behavour Type/Improvement Enhancement to language design
Projects
None yet
Development

No branches or pull requests

4 participants