HaxeFoundation / HaxeFoundation/haxe
GADT type params and inlining
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
I extracted this from `tink_sql`:
```haxe
enum ExprData {
EBinOp(op:BinOp, a:Expr, b:Expr):ExprData;
}
enum BinOp {
Like:BinOp;
}
abstract Expr(ExprData) {
inline function new(e) {
this = e;
}
@:from static function ofData(d:ExprData):Expr {
return new Expr(d);
}
public function like(b:Expr):Expr {
return EBinOp(Like, this, b);
}
}
```
My first question is whether the `like` method should compile? Because within that function `this` is `ExprData`, where `T` is supposed to be an unconstrained type parameter and it doesn't sound like it should pass the `T:String` constraint check of `Like`.
Secondly, if we add `inline` to the `ofData` method, we actually get an error talking about this:
```
src/Main.hx:19: characters 23-27 : error: Expr.T should be String
src/Main.hx:19: characters 23-27 : ... have: (ExprData) -> ...
src/Main.hx:19: characters 23-27 : ... want: (ExprData) -> ...
src/Main.hx:19: characters 23-27 : ... For function argument 'a'
```
And thirdly, looks like `have` and `want` are swapped in this error message?
Contributor guide
Assessment
This issue has not been assessed yet.