1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 01:52:11 +03:00

Fix record creation error message location (#2424)

* Closes #2422
This commit is contained in:
Łukasz Czajka 2023-10-04 12:47:24 +02:00 committed by GitHub
parent 6b38543ae3
commit 286cdb0026
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -2088,7 +2088,7 @@ checkRecordCreation RecordCreation {..} = do
Just ci -> do Just ci -> do
let name = NameUnqualified (ci ^. constructorInfoTypeName . nameConcrete) let name = NameUnqualified (ci ^. constructorInfoTypeName . nameConcrete)
nameId = ci ^. constructorInfoTypeName . S.nameId nameId = ci ^. constructorInfoTypeName . S.nameId
info <- getRecordInfo' name nameId info <- getRecordInfo' (getLoc _recordCreationConstructor) name nameId
let sig = info ^. recordInfoSignature let sig = info ^. recordInfoSignature
(vars', fields') <- withLocalScope $ localBindings $ ignoreSyntax $ do (vars', fields') <- withLocalScope $ localBindings $ ignoreSyntax $ do
vs <- mapM (reserveFunctionSymbol . (^. fieldDefineFunDef)) _recordCreationFields vs <- mapM (reserveFunctionSymbol . (^. fieldDefineFunDef)) _recordCreationFields
@ -2201,19 +2201,20 @@ getRecordInfo ::
(Members '[State ScoperState, Error ScoperError] r) => (Members '[State ScoperState, Error ScoperError] r) =>
ScopedIden -> ScopedIden ->
Sem r RecordInfo Sem r RecordInfo
getRecordInfo indTy = getRecordInfo' (indTy ^. scopedIdenFinal . nameConcrete) (indTy ^. scopedIdenFinal . S.nameId) getRecordInfo indTy = getRecordInfo' (getLoc indTy) (indTy ^. scopedIdenFinal . nameConcrete) (indTy ^. scopedIdenFinal . S.nameId)
getRecordInfo' :: getRecordInfo' ::
forall r. forall r.
(Members '[State ScoperState, Error ScoperError] r) => (Members '[State ScoperState, Error ScoperError] r) =>
Interval ->
Name -> Name ->
NameId -> NameId ->
Sem r RecordInfo Sem r RecordInfo
getRecordInfo' name nameId = getRecordInfo' loc name nameId =
fromMaybeM err (gets (^. scoperRecordFields . at nameId)) fromMaybeM err (gets (^. scoperRecordFields . at nameId))
where where
err :: Sem r a err :: Sem r a
err = throw (ErrNotARecord (NotARecord name)) err = throw (ErrNotARecord (NotARecord name loc))
getNameSignature :: (Members '[State ScoperState, Error ScoperError] r) => ScopedIden -> Sem r NameSignature getNameSignature :: (Members '[State ScoperState, Error ScoperError] r) => ScopedIden -> Sem r NameSignature
getNameSignature s = do getNameSignature s = do

View File

@ -751,8 +751,9 @@ instance ToGenericError ConstructorNotARecord where
i :: Interval i :: Interval
i = getLoc _constructorNotARecord i = getLoc _constructorNotARecord
newtype NotARecord = NotARecord data NotARecord = NotARecord
{ _notARecord :: Name { _notARecord :: Name,
_notARecordLocation :: Interval
} }
deriving stock (Show) deriving stock (Show)
@ -771,7 +772,7 @@ instance ToGenericError NotARecord where
} }
where where
i :: Interval i :: Interval
i = getLoc _notARecord i = _notARecordLocation
newtype UnexpectedField = UnexpectedField newtype UnexpectedField = UnexpectedField
{ _unexpectedField :: Symbol { _unexpectedField :: Symbol