Skip to content

Commit

Permalink
allow parsing postfix ! but fail during typing (closes #4284)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Nov 23, 2015
1 parent 0a4e7f8 commit 2a5c5cb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ast.ml
Expand Up @@ -465,8 +465,8 @@ let is_lower_ident i =
let pos = snd

let rec is_postfix (e,_) op = match op with
| Increment | Decrement -> true
| Not | Neg | NegBits -> false
| Increment | Decrement | Not -> true
| Neg | NegBits -> false

let is_prefix = function
| Increment | Decrement -> true
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/src/unit/issues/Issue4284.hx
@@ -0,0 +1,19 @@
package unit.issues;

private abstract A(String) {
public inline function new(s) this = s;

@:op(A!) function opNot() {
return this.toUpperCase();
}
}

class Issue4284 extends Test {
function test() {
var a = new A("foo");
eq("FOO", a!);

var b = true;
t(unit.TestType.typeError(b!));
}
}
1 change: 1 addition & 0 deletions typer.ml
Expand Up @@ -2342,6 +2342,7 @@ and type_unop ctx op flag e p =
let make e =
let t = (match op with
| Not ->
if flag = Postfix then error "Postfix ! is not supported" p;
unify ctx e.etype ctx.t.tbool e.epos;
ctx.t.tbool
| Increment
Expand Down

2 comments on commit 2a5c5cb

@nadako
Copy link
Member

@nadako nadako commented on 2a5c5cb Nov 24, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! Can't wait to try it in my codebase, since we use Maybe abstract a lot. Any reason it is in the issue_4603 instead of development?

@Simn
Copy link
Member Author

@Simn Simn commented on 2a5c5cb Nov 24, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to push it to development.

Please sign in to comment.