-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Don't allow the wrong monad in a bind whose pattern is a tuple pattern. The old saw produces a type error for that so we don't have to allow it now. 2. For binds in the wrong monad, unify the pattern type with the full wrong monadic type of the expression, not just the associated value type. This assigns the variables in the pattern types in the wrong monad, which matches both the historical behavior and also what happens inside the interpreter during execution. It also turns out that binds in the wrong monad with an explicit type signature expecting the bind to work didn't typecheck in the old saw. So we don't need to make that work as part of the workarounds either. Add three more test cases...
- Loading branch information
1 parent
df3b8c2
commit e53ce7c
Showing
7 changed files
with
96 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Loading file "err010.saw" | ||
err010.saw:12:1-12:9: Warning: Monadic bind with the wrong monad; found LLVMSetup but expected TopLevel | ||
err010.saw:12:1-12:9: Warning: This was historically ignored and will have no effect; if you really want to do this, prefix the expression with return | ||
err010.saw:12:1-12:9: Warning: This will become an error in a future release of SAW |
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,12 @@ | ||
// This was allowed prior to Dec 2024 and is currently a warning; | ||
// should eventually become an error. | ||
// | ||
// This case checks what happens if you take a tuple in the wrong | ||
// monad and bind it to a single value. | ||
|
||
let f x = do { | ||
llvm_assert {{ True }}; | ||
return (x, x); | ||
}; | ||
|
||
a <- f 0; |
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,15 @@ | ||
Loading file "err011.saw" | ||
err011.saw:11:11-11:14: Type mismatch. | ||
Mismatch of type constructors. Expected: TopLevel but got LLVMSetup | ||
err011.saw:11:1-11:14: The type TopLevel arises from this type annotation | ||
internal:1:9-1:18: The type LLVMSetup arises from this type annotation | ||
|
||
Expected: TopLevel | ||
Found: LLVMSetup | ||
|
||
Expected: TopLevel (t.0, t.1) | ||
Found: LLVMSetup (Int, Int) | ||
|
||
within "<toplevel>" (err011.saw:11:1-11:14) | ||
|
||
FAILED |
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,11 @@ | ||
// This was not allowed even prior to Dec 2024. | ||
// | ||
// This case checks what happens if you take a tuple in the wrong | ||
// monad and bind it to a tuple pattern. | ||
|
||
let f x = do { | ||
llvm_assert {{ True }}; | ||
return (x, x); | ||
}; | ||
|
||
(a, b) <- f 0; |
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,15 @@ | ||
Loading file "err012.saw" | ||
err012.saw:12:2-12:17: Warning: Monadic bind with the wrong monad; found LLVMSetup but expected TopLevel | ||
err012.saw:12:2-12:17: Warning: This was historically ignored and will have no effect; if you really want to do this, prefix the expression with return | ||
err012.saw:12:2-12:17: Warning: This will become an error in a future release of SAW | ||
err012.saw:12:14-12:17: Type mismatch. | ||
Mismatch of type constructors. Expected: Int but got <Block> | ||
err012.saw:12:6-12:9: The type Int arises from this type annotation | ||
err012.saw:12:2-12:17: The type LLVMSetup Int arises from this type annotation | ||
|
||
Expected: Int | ||
Found: LLVMSetup Int | ||
|
||
within "<toplevel>" (err012.saw:12:2-12:17) | ||
|
||
FAILED |
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,12 @@ | ||
// This was not allowed even prior to Dec 2024. | ||
// | ||
// This case checks what happens if you take a value in the wrong | ||
// monad and bind it to a pattern that includes a type signature. | ||
|
||
let f x = do { | ||
llvm_assert {{ True }}; | ||
return x; | ||
}; | ||
|
||
// note that you need the parens because of a possibly silly parser issue | ||
(a : Int) <- f 3; |
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