Skip to content
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

Test unary operators that don't typecheck #473

Merged
merged 11 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/fail/bad-unops.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let a = ^3; // type error, operator is not defined for operand type
let b = ^-5; // type error, operator is not defined for operand type
let c : Nat = +3; // literal type mismatch
let d : Nat = -3; // literal type mismatch

switch (1) { case (^1) { ignore "hmmm" }; case _ { ignore "unexpected" } }; // type error, operator cannot consume expected type
switch (1) { case (+1) { ignore "unexpected" }; case _ { ignore "hmmm" } }; // literal type mismatch
switch (1) { case (-1) { ignore "hmmm" }; case _ { ignore "unexpected" } }; // literal type mismatch

switch (-1) { case (^1) { ignore "hmmm" }; case _ { ignore "unexpected" } }; // type error, operator cannot consume expected type
ignore (switch (-1) { case (+1) "hmmm"; case _ "as expected" });
ignore (switch (-1) { case (-1) "as expected"; case _ "hmmm" });

ignore (switch (^1 : Word8) { case (^1) "as expected"; case _ "hmmm" });
//switch (+1 : Word8) { case (+1) "as expected"; case _ "hmmm" }; // both `+1` are not accepted
ignore (switch (-1 : Word8) { case (-1) "as expected"; case _ "hmmm" });

// when testing the switch expression in the REPL, I either
// * expect the result being "as expected", or
// * a type error (as described in the comment)
//
// test steps wrapped in ignore should type-check
24 changes: 24 additions & 0 deletions test/fail/ok/bad-unops.tc.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
bad-unops.as:1.9-1.11: type error, operator is not defined for operand type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure where the Int is coming from, at least the parser isn't it:

$ src/asc -dp
ActorScript 0.1 interpreter
> let a = ^3;
(BlockE (LetD (VarP a) (UnE ??? NotOp (LitE (PreLit 3 Nat)))))
stdin:1.9-1.11: type error, operator is not defined for operand type
  Int

Int
bad-unops.as:2.9-2.12: type error, operator is not defined for operand type
Int
bad-unops.as:3.15-3.17: type error, literal of type
Int
does not have expected type
Nat
bad-unops.as:4.15-4.17: type error, literal of type
Int
does not have expected type
Nat
bad-unops.as:6.20-6.22: type error, operator cannot consume expected type
Nat
bad-unops.as:7.20-7.22: type error, literal of type
Int
does not have expected type
Nat
bad-unops.as:8.20-8.22: type error, literal of type
Int
does not have expected type
Nat
bad-unops.as:10.21-10.23: type error, operator cannot consume expected type
Int