-
Notifications
You must be signed in to change notification settings - Fork 34
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
comprehensions beginning with if clause #869
Comments
Should we also allow {String+} asSequence = { "element" }; would be a |
God no. I’ll try to implement this; let’s see how far I get. I think I’ve got the grammar part, now I have to fix the Visitors. |
Okay, I have something. I get 6 failures and 3 errors in the Also, I’m suspicious. That was way too easy. Let’s try if it works... |
Haha, yeah. It was too easy. For some reason I thought that if it compiles, then the rest happens automagically... I see two ways of making comprehensions with leading
The main difference between these is that in the hacky way, the conditions are evaluated when the Also, in case someone else wants to work for this, here are my grammar changes, and I’m pretty confident that these are sufficient. |
However you implemented, the condition needs to be evaluated lazily, each time the comprehension is evaluated. (Comprehensions can be reevaluated.) |
Progress report: I think I have implemented all necessary changes in the If anyone’s interested or wants to try and fix the error, here’s my current changes: https://gist.github.com/lucaswerkmeister/8466797 (copy, then |
Look at the generated .src, in theory you see it displayed before it crashes. |
I see it, looks as intended, compiles fine when I put it in its own file (and fix the .type.names). ----- Ursprüngliche Nachricht ----- Look at the generated .src, in theory you see it displayed before it crashes. |
Show me the .src and stack trace? |
When I'm home, ca. 1.5h ----- Ursprüngliche Nachricht ----- Show me the .src and stack trace? |
IMO it's the anonymous constructor block that is the issue. Looks like it was not declared properly in the AST. Try removing it. |
No that's crazy, this is already used now. Looks like the class symbol has a package kind. This is just crazy. |
I agree it’s crazy, because I get a different exception when I’m debugging from Eclipse than when I’m running it from the command line... But you’re actually right; at least when I’m debugging from Eclipse, javac gets an NPE because the I’ll fix that (initialize |
correction: not empty, the |
And it compiles!! |
Introduces the new abstract class InitialComprehensionClause as superclass of IfComprehensionClause and ForComprehensionClause to the tree.
Dammit! It works from the IDE and crashes with still the same error (kind 31 etc.) on the command line. |
Kind 31 is the I’m visiting my parents over the weekend, so unfortunately I won’t be able to work on this until sunday evening. If you want to try things out, you can see my two commits referenced above; that’s all I have. |
Actually... I was just able to compile and run the following code on my netbook: void run() {
{String*} strings = { if ("hi".contains("h")) "Hello, World!" };
print(strings.first);
} I’ll have to check why. Weird architecture bug (32/64-bit) or not caused by me and fixed in the meantime? (Interim report: typechecker and java backend apparently done, javascript backend todo.) |
Sounds good! |
This also significantly simplifies the $next$0() method – see the test case. CC ceylon/ceylon-spec#869
Alright, I think I have some implementation for the Javascript backend. However, I currently get:
Now that I’ve committed my changes, I can go back to Also, I got the error (kind 31) on the Java backend again, but then it suddenly vanished. Maybe ceylon/ceylon-compiler@024c4b8 fixed it? (Interim report: typechecker and java backend apparently done, javascript backend needs more testing and bugfixing.) |
* `(if)+ expression` did not have a "tail", i. e., did not return if the condition was false * `(if)+ (for) (if|for)* expression` wrote the "tail" before closing the "if"’s braces: a) double return inside the if, b) missing return outside the if part of ceylon/ceylon-spec#869
(that is, comprehensions without "for" clauses.) (Part of ceylon/ceylon-spec#869.)
Alright, I found and fixed the remaining known bug in the JS backend (spoiler: it was a really stupid one). I’ll write some more tests now, and then I think it’s time for a pull request! |
(that is, comprehensions without a "for" clause) The comprehension would return the result infinitely instead of only once. Still part of ceylon/ceylon-spec#869.
Phew! Pull requests opened. (Example code over at #908.) |
Awesome! Thanks! |
Suggested by @chochos [1]. I added another test to verify that conditions after a false condition are not evaluated: if (false) if (functionWithSideEffects()) value should not have side effects. [1] f8ef15c#commitcomment-5126747
Thanks, we'll take a look ASAP, and merge it. FTR we're going to try to move to a single repo real soon so you don't have to go through that pain again for pull requests. |
Cool, sounds good! FTR, I already started rebasing the branches locally to resolve conflicts ASAP (since this used to be scheduled for 1.2). No conflicts so far though. |
ETA? I have reviewed the typechecker changes, which look good, and am ready to push them. |
Introduces the new abstract class InitialComprehensionClause as superclass of IfComprehensionClause and ForComprehensionClause to the tree.
I have pushed the typechecker changes. Changes to |
This also significantly simplifies the $next$0() method – see the test case. CC ceylon/ceylon-spec#869
* `(if)+ expression` did not have a "tail", i. e., did not return if the condition was false * `(if)+ (for) (if|for)* expression` wrote the "tail" before closing the "if"’s braces: a) double return inside the if, b) missing return outside the if part of ceylon/ceylon-spec#869
(that is, comprehensions without "for" clauses.) (Part of ceylon/ceylon-spec#869.)
(that is, comprehensions without a "for" clause) The comprehension would return the result infinitely instead of only once. Still part of ceylon/ceylon-spec#869.
All done. Thanks, @lucaswerkmeister, great work! |
I have reviewed the jvm compiler changes and they seem very good, congrats! I have added some tests though, as I felt there were some cases missing. Do you mind adding runtime tests for this in the language module? We've had lots of bugs in comprehensions at runtime in the past and we absolutely need to test this, we can't rely just on how the compilation looks ;) Thanks! |
@chochos already bugged me about runtime tests :) he suggested a few, I added these and a few more in ceylon/ceylon.language@f8ef15c, ceylon/ceylon.language@4864b49. |
OK if you added them already then sorry, it's great :) |
Currently, a comprehension must begin with
for
. For #807 we should relax this restriction, and allow a comprehension to begin withif
. Then, for example:Evaluates to
{x}
ifx
exists, or to{}
otherwise.Likewise:
Evaluates to
[string]
ifstring
is not empty, or to[]
otherwise.The text was updated successfully, but these errors were encountered: