-
-
Notifications
You must be signed in to change notification settings - Fork 661
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
Support custom implicit Function Arguments like PosInfos via abstract @:fromNothing macro #6616
Closed
Closed
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3bd072a
allow @:fromNothing on abstracts (see #4583)
Simn 0624cc8
allow macro fromNothing calls for all optional args
frabbit 0e00944
add first fromNothing tests (bind is failing)
frabbit 82fb2b5
handle fromNothing when typing fn.bind
frabbit 711846f
refactor a little bit, fix ugly indentation
frabbit 304ef66
add more tests for fromNothing
frabbit dc37944
test @:fromNothing mono application
frabbit c46ee59
whitespace fix
frabbit 34ec43e
make sure we unify the abstract cast macro result with the expected t…
frabbit 1b1d78c
fix null padding on flash and php
frabbit 1a3e931
improve fromNothing tests, add tests for mixed arg cases (args with d…
frabbit 06f4841
just a test
frabbit 74c7651
minor fixes
frabbit 37d0d5f
Merge remote-tracking branch 'origin/development' into from_nothing
frabbit 294c914
Merge remote-tracking branch 'origin' into from_nothing
frabbit da214d9
Merge remote-tracking branch 'origin/development' into from_nothing
frabbit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package unit; | ||
|
||
#if macro | ||
import haxe.macro.Expr; | ||
import haxe.macro.Context; | ||
import haxe.macro.Type; | ||
#end | ||
|
||
|
||
|
||
@:forward | ||
@:callable | ||
@:arrayAccess | ||
@:extern | ||
private abstract Dep<T>(T) to T { | ||
|
||
private inline function new (x:T) { | ||
this = x; | ||
} | ||
|
||
|
||
@:from public static inline function fromT <T>(t:T):Dep<T> { | ||
return new Dep(t); | ||
} | ||
|
||
@:fromNothing macro public static function fromNothing ():Expr { | ||
var unexpected = () -> Context.fatalError("unexpected", Context.currentPos()); | ||
return switch Context.follow(Context.getExpectedType()) { | ||
case TAbstract(_.toString() => "unit._TestFromNothing.Dep", [t]): | ||
switch Context.follow(t) { | ||
case TAbstract(_.toString() => "Int", []): macro 1; | ||
case TAbstract(_.toString() => "unit._TestFromNothing.Int2", []): macro (2:Int2); | ||
case TAbstract(_.toString() => "unit._TestFromNothing.Int3", []): macro (3:Int3); | ||
case t: | ||
unexpected(); | ||
} | ||
case t: | ||
unexpected(); | ||
} | ||
} | ||
} | ||
#if !macro | ||
|
||
private abstract Int2(Int) from Int to Int {} | ||
|
||
private abstract Int3(Int) from Int to Int {} | ||
|
||
class TestFromNothing extends Test { | ||
|
||
function test1() { | ||
function foo1 (?a:Dep<Int>) { | ||
return a; | ||
} | ||
|
||
t(foo1() == 1); | ||
t(foo1(2) == 2); | ||
|
||
function foo2 (?a:Dep<Int>, ?b:Dep<Int>) { | ||
return (a:Int)+(b:Int); | ||
} | ||
|
||
t(foo2() == 2); | ||
t(foo2(2,3) == 5); | ||
t(foo2(2) == 3); | ||
|
||
function foo2 (?a:Dep<Int>, ?b:Dep<Int2>) { | ||
return (a:Int) + (b:Int); | ||
} | ||
|
||
function foo3 (?a:Dep<Int>, ?b:Dep<Int2>, ?c:Dep<Int3>) { | ||
return (a:Int) + (b:Int) + (c:Int); | ||
} | ||
|
||
t(foo2() == 3); | ||
t(foo3() == 6); | ||
|
||
t(foo2(7) == 9); | ||
t(foo3(7) == 12); | ||
|
||
t(foo2.bind()() == 3); | ||
t(foo3.bind()() == 6); | ||
|
||
t(foo2.bind(7)() == 9); | ||
t(foo3.bind(7)() == 12); | ||
|
||
t(foo2.bind(_)(7) == 9); | ||
t(foo2.bind(_,_)(7, 3) == 10); | ||
|
||
function foo4 <T>(x:T, plus:T->T->T, ?a:Dep<T>) { | ||
return plus(x, a); | ||
} | ||
|
||
t(foo4(1, (a, b) -> a + b) == 2); | ||
|
||
var f = foo4.bind(_, (a, b) -> a + b); | ||
t(f(1) == 2); | ||
|
||
t(foo4( (1:Int2), (a, b) -> (a:Int) + (b:Int) ) == 3); | ||
|
||
var f = foo4.bind(_, (a:Int2, b:Int2) -> ((a:Int) + (b:Int):Int2) ); | ||
t(f(1) == 3); | ||
|
||
function foo5 <T>(?x:Dep<T>, ?y:Dep<T>) { | ||
return Std.string(x) + "-" + Std.string(y); | ||
} | ||
|
||
t(foo5(3) == "3-1"); | ||
|
||
function foo (?x:Int = 5, ?y:Dep<Int>) { | ||
return Std.string(x) + "-" + Std.string(y); | ||
} | ||
|
||
t(foo() == "5-1"); | ||
t(foo.bind()() == "5-1"); | ||
|
||
function foo (?x:Dep<Int>, ?y:Int = 5) { | ||
return Std.string(x) + "-" + Std.string(y); | ||
} | ||
|
||
t(foo() == "1-5"); | ||
t(foo.bind()() == "1-5"); | ||
|
||
function foo (?w:Int = 7, ?x:Dep<Int>, ?y:Int = 5) { | ||
return Std.string(w) + "-" + Std.string(x) + "-" + Std.string(y); | ||
} | ||
|
||
t(foo() == "7-1-5"); | ||
|
||
t(foo.bind()() == "7-1-5"); | ||
|
||
function foo (?x:Int = 5, ?y:haxe.PosInfos) { | ||
var r = Std.string(x) + "-" + (y != null); | ||
return r; | ||
} | ||
|
||
t(foo.bind()() == "5-true"); | ||
|
||
} | ||
} | ||
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ncannasse does this change, actually ignoring pf_pad_null for bind, does have any effects on real code? The unit tests still pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well it's not ignoring pf_pad_null but is always pushing nulls whereas you're padding or not. I'm not sure I like it, but I guess we can remove extra nulls at a later stage maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, true. I actually wonder if and what implications this actually have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or to be more precise, which negative implications this have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and just to let you know, there are already cases where this leads to bugs: http://try-haxe.mrcdk.com/#12d04.