-
Notifications
You must be signed in to change notification settings - Fork 62
comprehensions beginning with if clause #3975
Comments
[@lucaswerkmeister] 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. |
[@lucaswerkmeister] 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... |
[@lucaswerkmeister] 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. |
[@gavinking] However you implemented, the condition needs to be evaluated lazily, each time the comprehension is evaluated. (Comprehensions can be reevaluated.) |
[@lucaswerkmeister] 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 |
[@FroMage] Look at the generated .src, in theory you see it displayed before it crashes. |
[@lucaswerkmeister] 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. |
[@FroMage] Show me the .src and stack trace? |
[@lucaswerkmeister] When I'm home, ca. 1.5h ----- Ursprüngliche Nachricht ----- Show me the .src and stack trace? |
[@lucaswerkmeister] Okay. Took a little longer that expected, because I fixed some other bugs first. This isn’t the same exception as yesterday night, but it’s close enough, I think. |
[@FroMage] IMO it's the anonymous constructor block that is the issue. Looks like it was not declared properly in the AST. Try removing it. |
[@FroMage] No that's crazy, this is already used now. Looks like the class symbol has a package kind. This is just crazy. |
[@lucaswerkmeister] 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 |
[@lucaswerkmeister] correction: not empty, the |
[@lucaswerkmeister] And it compiles!! |
[@lucaswerkmeister] Dammit! It works from the IDE and crashes with still the same error (kind 31 etc.) on the command line. |
[@lucaswerkmeister] 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. |
[@lucaswerkmeister] 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.) |
[@gavinking] Sounds good! |
[@lucaswerkmeister] 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.) |
[@lucaswerkmeister] 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! |
[@lucaswerkmeister] Phew! Pull requests opened. (Example code over at #4014.) |
[@gavinking] Awesome! Thanks! |
[@FroMage] 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. |
[@lucaswerkmeister] 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. |
[@gavinking] I have pushed the typechecker changes. Changes to |
[@gavinking] All done. Thanks, @lucaswerkmeister, great work! |
[@FroMage] 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! |
[@lucaswerkmeister] @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. |
[@FroMage] OK if you added them already then sorry, it's great :) |
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] lucaswerkmeister/ceylon.language@f8ef15c#commitcomment-5126747
* `(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 #3975
(that is, comprehensions without "for" clauses.) (Part of #3975.)
(that is, comprehensions without a "for" clause) The comprehension would return the result infinitely instead of only once. Still part of #3975.
This also significantly simplifies the $next$0() method – see the test case. CC #3975
This also significantly simplifies the $next$0() method – see the test case. CC #3975
Introduces the new abstract class InitialComprehensionClause as superclass of IfComprehensionClause and ForComprehensionClause to the tree.
[@gavinking] Currently, a comprehension must begin with
for
. For #3913 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.[Migrated from ceylon/ceylon-spec#869]
[Closed at 2014-01-28 11:57:01]
The text was updated successfully, but these errors were encountered: