-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Default function and conflicts detection #1800
Comments
3.) I think that this should compile without errors too:
returned error:
expected result:
|
I'm agreed with all three.
It's really primitive. (So there I put that "potential conflict" remark :) Technically I think it is possible to support multiple default calls correctly (as in above examples and similar cases) but this will require a full-featured analysis of all possible default() return value combinations somewhere at this point. Honestly i did not even try to craft such analysis in #1606 because at that time we weren't even sure if this feature is worth to be in at all so my main goal was to make it is as simple as possible (while meeting all base requirements like "independency of definition order" etc.). |
I have seen less.js code as I am porting it into java and actually found it clever. I really liked this trick. I think that main problem is that this exception is premature. What I'm trying to do is to categorize found mixins into categories and count how many of them are in each category:
Then I analyze numbers, somewhat like this:
I'm in the middle of trying to figure out those conditions :). So, if you want, I can either post them once I think it works and then reproduce them in javascript. Edit: so basically I'm doing what you suggests in your comment. |
Yes of course, for the analysis algorithm to work this L61 error condition needs to be removed.
Are you doing that in context of less4j? I'll be glad to port it back to javascript (though I'm not too familiar with Java I think I can read the code). |
Btw., I thought a bit more of (2) and indeed, this case makes sense in either way ("both expanded" and "consdered ambiguous"). It's hard to say which one would be more useful in isolation from possible use-cases... Maybe we could leave it "ambiguous" yet? (Assuming that its "ambiguity" detection moves to the new algorithm of course). But it's not that important yet again so either "just easier to detect" hadling will be OK. |
I think I got it here: https://github.com/SomMeri/less4j/blob/master/src/main/java/com/github/sommeri/less4j/core/compiler/stages/MixinsSolver.java#L114 Only mixins with right name, right number of parameters and matching patter enter the method (as third This is where I store candidates: https://github.com/SomMeri/less4j/blob/master/src/main/java/com/github/sommeri/less4j/core/compiler/stages/MixinsSolver.java#L120 Each mixin is categorized as one of: DEFAULT_OBLIVIOUS, ONLY_IF_DEFAULT, ONLY_IF_NOT_DEFAULT
Which categories to use is evaluated on this line using logic implemented in this method. Logic:
At that point, we know that:
Therefore, we there are either:
The rest of logic:
|
I wrote all that yesterday evening, so your last comment is not implemented there. However, it should be easy to change that. If you want, I will change it, but now I run out of time now. The change would go here. Unit tests (less): Expected css is in the same directory in file with the same name and css suffix:
|
Oh, thanks! I'll try to implement this in js. |
I updated my implementation to check for multiple not default here It now stars by:
However, while doing that, I found this (so the condition is not completely done). If this is supposed to fail - and fails currently in less.js:
shouldnt this fail too?
and this too:
Last to two less files compile into nothing. |
By "fail" do you mean throwing a error? |
@seven-phases-max I meant throwing an error. It seemed to be logical, but now I think I just got confused. There were too many possibilities. Alright, it is as it is and I'm not going to touch it further. |
@SomMeri In summary: Changes from current less.js:The conflict detection is less restrictive now, it does not throw a error until conflicting conditions are actually about to be expanded. The most notable example:
Differences from less4j:(A) Additional examples has the following test case marked as not ambiguous (unfortunately I noticed it only when I've started to update/collect tests):
But it is ambiguous. There both conditions recursively depend on each other. Both default() calls can't return true or false without changing the result of the other and therefore reverting back its own return value. And several examples in error handling file: (B) L8: same as (A). (C) L21: No conflict there because the first unconditional mixin makes all default() calls return false. (D) L55: Produces error. It's a bit tricky, the first mixing can't return true because that would make all three mixins to expand (i.e. making returned 'true' not valid), so it could return false but this makes the whole snippet to be equal to L41 (i.e. considered as ambiguous). (E) L56: Should produce error (it's the same code as L41). |
Can we close this now? I think its into the realms of not going to affect anyone? |
Yes, I guess we can close this (and we can always re-open if something new of the subject pops up). |
@seven-phases-max Thank you for detailed description. "Infinite uncertainties" is perfect description to what happened to my brain while trying to implement this. |
1.) This is considered to be ambiguous, but I do not think it should be:
error:
Expected result:
2-question.) This is considered ambiguous too, was that intentional? It more or less makes sense either way.
The text was updated successfully, but these errors were encountered: