8000 New unstructured error `IdiomBracketError` by andreasabel · Pull Request #7461 · agda/agda · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
< 8000 turbo-frame id="repo-content-turbo-frame" target="_top" data-turbo-action="advance" class="">

New unstructured error IdiomBracketError #7461

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

Merged
merged 1 commit into from
Aug 31, 2024
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
1 change: 1 addition & 0 deletions src/full/Agda/Interaction/Options/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ data ErrorName
| GeneralizeNotSupportedHere_
| GeneralizedVarInLetOpenedModule_
| HidingMismatch_
| IdiomBracketError_
| IllTypedPatternAfterWithAbstraction_
| IllegalDeclarationInDataDefinition_
| IllegalHidingInPostfixProjection_
Expand Down
11 changes: 7 additions & 4 deletions src/full/Agda/Syntax/IdiomBrackets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ appViewM = \case
where
onlyVisible a
| defaultNamedArg () == fmap (() <$) a = return $ namedArg a
| otherwise = genericError "Only regular arguments are allowed in idiom brackets (no implicit or instance arguments)"
noPlaceholder Placeholder{} = genericError "Naked sections are not allowed in idiom brackets"
| otherwise = idiomBracketError "Only regular arguments are allowed in idiom brackets (no implicit or instance arguments)"
noPlaceholder Placeholder{} = idiomBracketError "Naked sections are not allowed in idiom brackets"
noPlaceholder (NoPlaceholder _ x) = return x

ordinary (Ordinary a) = return a
ordinary _ = genericError "Binding syntax is not allowed in idiom brackets"
ordinary _ = idiomBracketError "Binding syntax is not allowed in idiom brackets"

ensureInScope :: QName -> ScopeM ()
ensureInScope q = do
r <- resolveName q
case r of
UnknownName -> genericError $
UnknownName -> idiomBracketError $
prettyShow q ++ " needs to be in scope to use idiom brackets " ++ prettyShow leftIdiomBrkt ++ " ... " ++ prettyShow rightIdiomBrkt
_ -> return ()

idiomBracketError :: String -> ScopeM a
idiomBracketError = typeError . IdiomBracketError
2 changes: 2 additions & 0 deletions src/full/Agda/TypeChecking/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ instance PrettyTCM TypeError where

SyntaxError s -> fwords $ "Syntax error: " ++ s

IdiomBracketError err -> fwords err

NoKnownRecordWithSuchFields fields -> fsep $
case fields of
[] -> pwords "There are no records in scope"
Expand Down
1 change: 1 addition & 0 deletions src/full/Agda/TypeChecking/Errors/Names.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ typeErrorName = \case
GeneralizeNotSupportedHere {} -> GeneralizeNotSupportedHere_
GeneralizedVarInLetOpenedModule {} -> GeneralizedVarInLetOpenedModule_
HidingMismatch {} -> HidingMismatch_
IdiomBracketError {} -> IdiomBracketError_
IllTypedPatternAfterWithAbstraction {} -> IllTypedPatternAfterWithAbstraction_
IllegalDeclarationInDataDefinition {} -> IllegalDeclarationInDataDefinition_
IllegalHidingInPostfixProjection {} -> IllegalHidingInPostfixProjection_
Expand Down
3 changes: 3 additions & 0 deletions src/full/Agda/TypeChecking/Monad/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4724,6 +4724,9 @@ data TypeError
-- ^ Error thrown by the option parser.
| NicifierError DeclarationException'
-- ^ Error thrown in the nicifier phase 'Agda.Syntax.Concrete.Definitions'.
| IdiomBracketError String
-- ^ Error during (operator) parsing and interpreting the contents of idiom brackets.
-- Error message in 'String'.
| NoKnownRecordWithSuchFields [C.Name]
-- ^ The user has given a record expression with the given fields,
-- but no record type known to type inference has all these fields.
Expand Down
16 changes: 16 additions & 0 deletions test/Fail/BindingsInIdiomBrackets.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Andreas, 2024-08-29
-- Trigger error "Binding syntax is not allowed in idiom brackets"

postulate
F : Set → Set
pure : ∀ {A} → A → F A
_<*>_ : ∀ {A B} → F (A → B) → F A → F B

bind : ∀ {A B} → F A → (A → F B) → F B

syntax bind m (λ x → k) = x ← m then k

_ = (| _ ← _ then _ |)

-- Expected error:
-- Binding syntax is not allowed in idiom brackets
3 changes: 3 additions & 0 deletions test/Fail/BindingsInIdiomBrackets.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BindingsInIdiomBrackets.agda:13,5-23: error: [IdiomBracketError]
Binding syntax is not allowed in idiom brackets
when scope checking ⦇ _ ← _ then _ ⦈
2 changes: 1 addition & 1 deletion test/Fail/IdiomBracketsImplicit.err
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IdiomBracketsImplicit.agda:22,15-37: error: [GenericError]
IdiomBracketsImplicit.agda:22,15-37: error: [IdiomBracketError]
Only regular arguments are allowed in idiom brackets (no implicit
or instance arguments)
when scope checking ⦇ _∷_ {n = n} a as ⦈
2 changes: 1 addition & 1 deletion test/Fail/IdiomBracketsNotInScope.err
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
IdiomBracketsNotInScope.agda:12,10-21: error: [GenericError]
IdiomBracketsNotInScope.agda:12,10-21: error: [IdiomBracketError]
_<*>_ needs to be in scope to use idiom brackets ⦇ ... ⦈
when scope checking ⦇ suc a ⦈
38 changes: 38 additions & 0 deletions test/Fail/SectionsInIdiomBrackets.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-- Andreas, 2024-08-29
-- Sections not allowed in idiom brackets

postulate
F : Set → Set
pure : ∀ {A} → A → F A
_<*>_ : ∀ {A B} → F (A → B) → F A → F B

postulate
A : Set
_⊕_ : A → A → A
a b c : F A
f : A → A → A

infixl 5 _⊕_

-- Various experiments:

_ = (| f |)
_ = (| f a |)
_ = (| f a b |)
_ = (| λ x y → f x y |) -- same as (| f |)
-- _ = (| λ x → f a x |) -- (F A) !=< A
-- _ = (| (f a) b |) -- (F A) !=< A

_ = (| (| a ⊕ b |) ⊕ c |) -- Accepted
-- _ = (| a ⊕ b ⊕ c |) -- Ill-typed

accepted0 = (| _⊕_ |)
accepted2 = (| a ⊕ b |)

-- Trigger error:

-- rejected1 = (| λ x → a ⊕ x |)
-- rejected1 = (| a ⊕_ |)
rejected1 = (| _⊕ b |)

-- Error: Naked sections are not allowed in idiom brackets
3 changes: 3 additions & 0 deletions test/Fail/SectionsInIdiomBrackets.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SectionsInIdiomBrackets.agda:36,13-24: error: [IdiomBracketError]
Naked sections are not allowed in idiom brackets
when scope checking ⦇ _⊕ b ⦈
Loading
0