@@ -19,6 +19,10 @@ module Kore.ASTVerifier.AttributesVerifier
1919 ) where
2020
2121import qualified Control.Lens as Lens
22+ import Data.Foldable
23+ ( find
24+ , for_
25+ )
2226import Data.Generics.Product
2327import Prelude.Kore
2428
@@ -28,6 +32,7 @@ import qualified Data.Functor.Foldable as Recursive
2832import Kore.ASTVerifier.Error
2933import qualified Kore.Attribute.Axiom as Attribute
3034 ( Axiom
35+ , sourceLocation
3136 )
3237import Kore.Attribute.Hook
3338import Kore.Attribute.Overload
@@ -37,6 +42,9 @@ import Kore.Attribute.Sort
3742import Kore.Attribute.Sort.HasDomainValues
3843import Kore.Attribute.Subsort as Subsort
3944
45+ import Kore.AST.AstWithLocation
46+ ( locationFromAst
47+ )
4048import qualified Kore.Attribute.Parser as Attribute.Parser
4149import qualified Kore.Attribute.Symbol as Attribute
4250import Kore.Error
@@ -50,11 +58,18 @@ import Kore.Syntax.Application
5058 ( SymbolOrAlias (.. )
5159 )
5260import Kore.Syntax.Definition
61+ import Kore.Syntax.Id
62+ ( prettyPrintAstLocation
63+ )
5364import Kore.Syntax.Pattern
5465import Kore.Syntax.Variable
5566 ( VariableName (.. )
5667 )
68+ import Kore.Unparser
69+ ( unparse
70+ )
5771import qualified Kore.Verified as Verified
72+ import Pretty
5873
5974parseAttributes :: MonadError (Error VerifyError ) m => Attributes -> m Hook
6075parseAttributes = Attribute.Parser. liftParser . Attribute.Parser. parseAttributes
@@ -138,11 +153,29 @@ verifyNoHookAttribute attributes = do
138153
139154verifyNoHookedSupersort
140155 :: MonadError (Error VerifyError ) error
141- => [Kore.Attribute.Sort. Sort ]
156+ => IndexedModule Verified. Pattern Attribute. Symbol attrs
157+ -> Attribute. Axiom SymbolOrAlias VariableName
158+ -> [Subsort. Subsort ]
142159 -> error ()
143- verifyNoHookedSupersort supersortsAtts = do
144- let isHooked = getHasDomainValues . hasDomainValues <$> supersortsAtts
145- when (or isHooked) $ koreFail " Hooked sorts may not have subsorts."
160+ verifyNoHookedSupersort indexedModule axiom subsorts = do
161+ let isHooked =
162+ getHasDomainValues . hasDomainValues
163+ . getSortAttributes indexedModule
164+ . Subsort. supersort
165+ hookedSubsort = find isHooked subsorts
166+ for_ hookedSubsort $ \ sort ->
167+ koreFail . unlines $
168+ [ " Hooked sorts may not have subsorts."
169+ , " Hooked sort:"
170+ , show . unparse $ Subsort. supersort sort
171+ , " Its subsort:"
172+ , show . unparse $ Subsort. subsort sort
173+ , " Location in the Kore file:"
174+ , show . prettyPrintAstLocation
175+ $ locationFromAst (Subsort. supersort sort)
176+ , " Location in the original K file: "
177+ , show . pretty $ Attribute. sourceLocation axiom
178+ ]
146179
147180verifyAxiomAttributes
148181 :: forall error attrs
@@ -152,9 +185,8 @@ verifyAxiomAttributes
152185 -> error (Attribute. Axiom Internal.Symbol. Symbol VariableName )
153186verifyAxiomAttributes indexedModule axiom = do
154187 let overload = axiom Lens. ^. field @ " overload"
155- supersorts = Subsort. supersort <$> getSubsorts (axiom Lens. ^. field @ " subsorts" )
156- supersortsAtts = getSortAttributes indexedModule <$> supersorts
157- verifyNoHookedSupersort supersortsAtts
188+ subsorts = getSubsorts (axiom Lens. ^. field @ " subsorts" )
189+ verifyNoHookedSupersort indexedModule axiom subsorts
158190 case getOverload overload of
159191 Nothing -> do
160192 let newOverload = Overload Nothing
0 commit comments