add @[fail] modifier to declarations

- `@[fail] def foo = ...` succeeds if `foo` has some error.
- `@[fail "scope"] def foo = ...` succeeds if `foo` has some error
  containing the word "scope" somewhere
- `@[fail] namespace foo { }` works too and the error must be anywhere
  in the namespace
This commit is contained in:
rhiannon morris 2023-09-22 01:29:23 +02:00
parent ea674503c0
commit d4cfbd4045
6 changed files with 127 additions and 41 deletions

View file

@ -30,6 +30,8 @@ data Error =
| DisplacedBoundVar Loc PName
| WrapTypeError TypeError
| LoadError Loc FilePath FileError
| ExpectedFail Loc
| WrongFail String Error Loc
| WrapParseError String ParseError
@ -106,5 +108,13 @@ parameters (showContext : Bool)
"couldn't load file" <++> text file,
text $ show err]
prettyError (ExpectedFail loc) = pure $
sep [!(prettyLoc loc), "expected error"]
prettyError (WrongFail str err loc) = pure $
sep [!(prettyLoc loc),
"wrong error, expected to match", !(hl Tag $ text "\"\{str}\""),
"but got", !(prettyError err)]
prettyError (WrapParseError file err) =
prettyParseError file err