Merge pull request #2240 from unisonweb/fix/2238

Don't allow docEval and docEvalInline to use other abilities
This commit is contained in:
Paul Chiusano 2021-07-16 13:17:21 -04:00 committed by GitHub
commit 19125d7c2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 0 deletions

View File

@ -591,7 +591,9 @@ syntax.docEmbedSignatureLink tm =
syntax.docCode c = Code c
syntax.docCodeBlock typ c = CodeBlock typ (docWord c)
syntax.docVerbatim c = CodeBlock "raw" c
syntax.docEval : '{} a -> Doc2
syntax.docEval d = Special (Eval (Doc2.term d))
syntax.docEvalInline : '{} a -> Doc2
syntax.docEvalInline a = Special (EvalInline (Doc2.term a))
syntax.docExample n a = Special (Example n (Doc2.term a))
syntax.docExampleBlock n a = Special (ExampleBlock n (Doc2.term a))

View File

@ -27,6 +27,7 @@ import Unison.NamePrinter ( styleHashQualified'' )
import qualified Unison.Pattern as Pattern
import Unison.Pattern ( Pattern )
import Unison.Reference ( Reference )
import qualified Unison.Reference as Reference
import qualified Unison.Referent as Referent
import Unison.Referent ( Referent )
import qualified Unison.Util.SyntaxText as S
@ -1380,11 +1381,22 @@ toDocVerbatim _ _ = Nothing
toDocEval :: Ord v => PrettyPrintEnv -> Term3 v PrintAnnotation -> Maybe (Term3 v PrintAnnotation)
toDocEval ppe (App' (Ref' r) (Delay' tm))
| nameEndsWith ppe ".docEval" r = Just tm
| r == _oldDocEval = Just tm
toDocEval _ _ = Nothing
-- Old hashes for docEval, docEvalInline w/ incorrect type signatures.
-- They are still used by some existing docs so the pretty-printer
-- recognizes it.
--
-- See https://github.com/unisonweb/unison/issues/2238
_oldDocEval, _oldDocEvalInline :: Reference
_oldDocEval = Reference.unsafeFromText "#0ua7gqa7kqnj80ulhmtcqsfgalmh4g9kg198dt2uen0s0jeebbo4ljnj4133cn1kbm38i2q3joivodtfei3jfln5scof0r0381k8dm0"
_oldDocEvalInline = Reference.unsafeFromText "#maleg6fmu3j0k0vgm99lgrsnhio3ba750hcainuv5jdi9scdsg43hpicmf6lovsa0mnaija7bjebnr5nas3qsj4r087hur1jh0rsfso"
toDocEvalInline :: Ord v => PrettyPrintEnv -> Term3 v PrintAnnotation -> Maybe (Term3 v PrintAnnotation)
toDocEvalInline ppe (App' (Ref' r) (Delay' tm))
| nameEndsWith ppe ".docEvalInline" r = Just tm
| r == _oldDocEvalInline = Just tm
toDocEvalInline _ _ = Nothing
toDocExample, toDocExampleBlock :: Ord v => PrettyPrintEnv -> Term3 v PrintAnnotation -> Maybe (Term3 v PrintAnnotation)

View File

@ -0,0 +1,18 @@
```ucm:hide
.> builtins.mergeio
```
This should not typecheck - the inline `@eval` expression uses abilities.
```unison:error
ability Abort where abort : x
ex = {{ @eval{abort} }}
```
This file should also not typecheck - it has a triple backticks block that uses abilities.
```ucm:error
.> load unison-src/transcripts/fix2238.u
```

View File

@ -0,0 +1,28 @@
This should not typecheck - the inline `@eval` expression uses abilities.
```unison
ability Abort where abort : x
ex = {{ @eval{abort} }}
```
```ucm
The expression in red needs the {Abort} ability, but this location does not have access to any abilities.
3 | ex = {{ @eval{abort} }}
```
This file should also not typecheck - it has a triple backticks block that uses abilities.
```ucm
.> load unison-src/transcripts/fix2238.u
The expression in red needs the {Abort} ability, but this location does not have access to any abilities.
7 | abort + 1
```

View File

@ -0,0 +1,9 @@
ability Abort where abort : x
ex = {{
```
abort + 1
```
}}