Skip to content
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

Fix record creation error message location #2424

Merged
merged 1 commit into from
Oct 4, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ checkRecordCreation RecordCreation {..} = do
Just ci -> do
let name = NameUnqualified (ci ^. constructorInfoTypeName . nameConcrete)
nameId = ci ^. constructorInfoTypeName . S.nameId
info <- getRecordInfo' name nameId
info <- getRecordInfo' (getLoc _recordCreationConstructor) name nameId
let sig = info ^. recordInfoSignature
(vars', fields') <- withLocalScope $ localBindings $ ignoreSyntax $ do
vs <- mapM (reserveFunctionSymbol . (^. fieldDefineFunDef)) _recordCreationFields
Expand Down Expand Up @@ -2201,19 +2201,20 @@ getRecordInfo ::
(Members '[State ScoperState, Error ScoperError] r) =>
ScopedIden ->
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' ::
forall r.
(Members '[State ScoperState, Error ScoperError] r) =>
Interval ->
Name ->
NameId ->
Sem r RecordInfo
getRecordInfo' name nameId =
getRecordInfo' loc name nameId =
fromMaybeM err (gets (^. scoperRecordFields . at nameId))
where
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 s = do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,9 @@ instance ToGenericError ConstructorNotARecord where
i :: Interval
i = getLoc _constructorNotARecord

newtype NotARecord = NotARecord
{ _notARecord :: Name
data NotARecord = NotARecord
{ _notARecord :: Name,
_notARecordLocation :: Interval
}
deriving stock (Show)

Expand All @@ -771,7 +772,7 @@ instance ToGenericError NotARecord where
}
where
i :: Interval
i = getLoc _notARecord
i = _notARecordLocation

newtype UnexpectedField = UnexpectedField
{ _unexpectedField :: Symbol
Expand Down