git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Improve import/export errors for unknown values
10ffc2dGary Burgess
src/Language/PureScript/Errors.hs+108−76
@@ -75,6 +75,14 @@ data SimpleErrorMessage
75 | UnknownValue (Qualified Ident)
75 | UnknownValue (Qualified Ident)
76 | UnknownDataConstructor (Qualified ProperName) (Maybe (Qualified ProperName))
76 | UnknownDataConstructor (Qualified ProperName) (Maybe (Qualified ProperName))
77 | UnknownTypeConstructor (Qualified ProperName)
77 | UnknownTypeConstructor (Qualified ProperName)
78+ | UnknownImportType ModuleName ProperName
79+ | UnknownExportType ProperName
80+ | UnknownImportTypeClass ModuleName ProperName
81+ | UnknownExportTypeClass ProperName
82+ | UnknownImportValue ModuleName Ident
83+ | UnknownExportValue Ident
84+ | UnknownImportDataConstructor ModuleName ProperName ProperName
85+ | UnknownExportDataConstructor ProperName ProperName
78 | ConflictingImport String ModuleName
86 | ConflictingImport String ModuleName
79 | ConflictingImports String ModuleName ModuleName
87 | ConflictingImports String ModuleName ModuleName
80 | ConflictingTypeDecls ProperName
88 | ConflictingTypeDecls ProperName
@@ -164,82 +172,90 @@ instance UnificationError Kind ErrorMessage where
164--
172--
165errorCode :: ErrorMessage -> String
173errorCode :: ErrorMessage -> String
166errorCode em = case unwrapErrorMessage em of
174errorCode em = case unwrapErrorMessage em of
167− (ErrorParsingExterns _) -> "ErrorParsingExterns"
175+ ErrorParsingExterns{} -> "ErrorParsingExterns"
168− (ErrorParsingFFIModule _) -> "ErrorParsingFFIModule"
176+ ErrorParsingFFIModule{} -> "ErrorParsingFFIModule"
169− (ErrorParsingModule _) -> "ErrorParsingModule"
177+ ErrorParsingModule{} -> "ErrorParsingModule"
170− MissingFFIModule{} -> "MissingFFIModule"
178+ MissingFFIModule{} -> "MissingFFIModule"
171− MultipleFFIModules{} -> "MultipleFFIModules"
179+ MultipleFFIModules{} -> "MultipleFFIModules"
172− UnnecessaryFFIModule{} -> "UnnecessaryFFIModule"
180+ UnnecessaryFFIModule{} -> "UnnecessaryFFIModule"
173− (InvalidExternsFile _) -> "InvalidExternsFile"
181+ InvalidExternsFile{} -> "InvalidExternsFile"
174− (CannotGetFileInfo _) -> "CannotGetFileInfo"
182+ CannotGetFileInfo{} -> "CannotGetFileInfo"
175− (CannotReadFile _) -> "CannotReadFile"
183+ CannotReadFile{} -> "CannotReadFile"
176− (CannotWriteFile _) -> "CannotWriteFile"
184+ CannotWriteFile{} -> "CannotWriteFile"
177− (InfiniteType _) -> "InfiniteType"
185+ InfiniteType{} -> "InfiniteType"
178− (InfiniteKind _) -> "InfiniteKind"
186+ InfiniteKind{} -> "InfiniteKind"
179− CannotReorderOperators -> "CannotReorderOperators"
187+ CannotReorderOperators -> "CannotReorderOperators"
180− (MultipleFixities _) -> "MultipleFixities"
188+ MultipleFixities{} -> "MultipleFixities"
181− (OrphanTypeDeclaration _) -> "OrphanTypeDeclaration"
189+ OrphanTypeDeclaration{} -> "OrphanTypeDeclaration"
182− (OrphanFixityDeclaration _) -> "OrphanFixityDeclaration"
190+ OrphanFixityDeclaration{} -> "OrphanFixityDeclaration"
183− (RedefinedModule _ _) -> "RedefinedModule"
191+ RedefinedModule{} -> "RedefinedModule"
184− (RedefinedIdent _) -> "RedefinedIdent"
192+ RedefinedIdent{} -> "RedefinedIdent"
185− OverlappingNamesInLet -> "OverlappingNamesInLet"
193+ OverlappingNamesInLet -> "OverlappingNamesInLet"
186− (UnknownModule _) -> "UnknownModule"
194+ UnknownModule{} -> "UnknownModule"
187− (UnknownType _) -> "UnknownType"
195+ UnknownType{} -> "UnknownType"
188− (UnknownTypeClass _) -> "UnknownTypeClass"
196+ UnknownTypeClass{} -> "UnknownTypeClass"
189− (UnknownValue _) -> "UnknownValue"
197+ UnknownValue{} -> "UnknownValue"
190− (UnknownDataConstructor _ _) -> "UnknownDataConstructor"
198+ UnknownDataConstructor{} -> "UnknownDataConstructor"
191− (UnknownTypeConstructor _) -> "UnknownTypeConstructor"
199+ UnknownTypeConstructor{} -> "UnknownTypeConstructor"
200+ UnknownImportType{} -> "UnknownImportType"
201+ UnknownExportType{} -> "UnknownExportType"
202+ UnknownImportTypeClass{} -> "UnknownImportTypeClass"
203+ UnknownExportTypeClass{} -> "UnknownExportTypeClass"
204+ UnknownImportValue{} -> "UnknownImportValue"
205+ UnknownExportValue{} -> "UnknownExportValue"
206+ UnknownImportDataConstructor{} -> "UnknownImportDataConstructor"
207+ UnknownExportDataConstructor{} -> "UnknownExportDataConstructor"
192− (ConflictingImport _ _) -> "ConflictingImport"
208+ ConflictingImport{} -> "ConflictingImport"
193− (ConflictingImports _ _ _) -> "ConflictingImports"
209+ ConflictingImports{} -> "ConflictingImports"
194− (ConflictingTypeDecls _) -> "ConflictingTypeDecls"
210+ ConflictingTypeDecls{} -> "ConflictingTypeDecls"
195− (ConflictingCtorDecls _) -> "ConflictingCtorDecls"
211+ ConflictingCtorDecls{} -> "ConflictingCtorDecls"
196− (TypeConflictsWithClass _) -> "TypeConflictsWithClass"
212+ TypeConflictsWithClass{} -> "TypeConflictsWithClass"
197− (CtorConflictsWithClass _) -> "CtorConflictsWithClass"
213+ CtorConflictsWithClass{} -> "CtorConflictsWithClass"
198− (ClassConflictsWithType _) -> "ClassConflictsWithType"
214+ ClassConflictsWithType{} -> "ClassConflictsWithType"
199− (ClassConflictsWithCtor _) -> "ClassConflictsWithCtor"
215+ ClassConflictsWithCtor{} -> "ClassConflictsWithCtor"
200− (DuplicateClassExport _) -> "DuplicateClassExport"
216+ DuplicateClassExport{} -> "DuplicateClassExport"
201− (DuplicateValueExport _) -> "DuplicateValueExport"
217+ DuplicateValueExport{} -> "DuplicateValueExport"
202− (DuplicateTypeArgument _) -> "DuplicateTypeArgument"
218+ DuplicateTypeArgument{} -> "DuplicateTypeArgument"
203− InvalidDoBind -> "InvalidDoBind"
219+ InvalidDoBind -> "InvalidDoBind"
204− InvalidDoLet -> "InvalidDoLet"
220+ InvalidDoLet -> "InvalidDoLet"
205− (CycleInDeclaration _) -> "CycleInDeclaration"
221+ CycleInDeclaration{} -> "CycleInDeclaration"
206− (CycleInTypeSynonym _) -> "CycleInTypeSynonym"
222+ CycleInTypeSynonym{} -> "CycleInTypeSynonym"
207− (CycleInModules _) -> "CycleInModules"
223+ CycleInModules{} -> "CycleInModules"
208− (NameIsUndefined _) -> "NameIsUndefined"
224+ NameIsUndefined{} -> "NameIsUndefined"
209− (NameNotInScope _) -> "NameNotInScope"
225+ NameNotInScope{} -> "NameNotInScope"
210− (UndefinedTypeVariable _) -> "UndefinedTypeVariable"
226+ UndefinedTypeVariable{} -> "UndefinedTypeVariable"
211− (PartiallyAppliedSynonym _) -> "PartiallyAppliedSynonym"
227+ PartiallyAppliedSynonym{} -> "PartiallyAppliedSynonym"
212− (EscapedSkolem _) -> "EscapedSkolem"
228+ EscapedSkolem{} -> "EscapedSkolem"
213− UnspecifiedSkolemScope -> "UnspecifiedSkolemScope"
229+ UnspecifiedSkolemScope -> "UnspecifiedSkolemScope"
214− (TypesDoNotUnify _ _) -> "TypesDoNotUnify"
230+ TypesDoNotUnify{} -> "TypesDoNotUnify"
215− (KindsDoNotUnify _ _) -> "KindsDoNotUnify"
231+ KindsDoNotUnify{} -> "KindsDoNotUnify"
216− (ConstrainedTypeUnified _ _) -> "ConstrainedTypeUnified"
232+ ConstrainedTypeUnified{} -> "ConstrainedTypeUnified"
217− (OverlappingInstances _ _ _) -> "OverlappingInstances"
233+ OverlappingInstances{} -> "OverlappingInstances"
218− (NoInstanceFound _ _) -> "NoInstanceFound"
234+ NoInstanceFound{} -> "NoInstanceFound"
219− (CannotDerive _ _) -> "CannotDerive"
235+ CannotDerive{} -> "CannotDerive"
220− (CannotFindDerivingType _) -> "CannotFindDerivingType"
236+ CannotFindDerivingType{} -> "CannotFindDerivingType"
221− (DuplicateLabel _ _) -> "DuplicateLabel"
237+ DuplicateLabel{} -> "DuplicateLabel"
222− (DuplicateValueDeclaration _) -> "DuplicateValueDeclaration"
238+ DuplicateValueDeclaration{} -> "DuplicateValueDeclaration"
223− (ArgListLengthsDiffer _) -> "ArgListLengthsDiffer"
239+ ArgListLengthsDiffer{} -> "ArgListLengthsDiffer"
224− (OverlappingArgNames _) -> "OverlappingArgNames"
240+ OverlappingArgNames{} -> "OverlappingArgNames"
225− (MissingClassMember _) -> "MissingClassMember"
241+ MissingClassMember{} -> "MissingClassMember"
226− (ExtraneousClassMember _) -> "ExtraneousClassMember"
242+ ExtraneousClassMember{} -> "ExtraneousClassMember"
227− (ExpectedType _) -> "ExpectedType"
243+ ExpectedType{} -> "ExpectedType"
228− (IncorrectConstructorArity _) -> "IncorrectConstructorArity"
244+ IncorrectConstructorArity{} -> "IncorrectConstructorArity"
229− SubsumptionCheckFailed -> "SubsumptionCheckFailed"
245+ SubsumptionCheckFailed -> "SubsumptionCheckFailed"
230− (ExprDoesNotHaveType _ _) -> "ExprDoesNotHaveType"
246+ ExprDoesNotHaveType{} -> "ExprDoesNotHaveType"
231− (PropertyIsMissing _ _) -> "PropertyIsMissing"
247+ PropertyIsMissing{} -> "PropertyIsMissing"
232− (CannotApplyFunction _ _) -> "CannotApplyFunction"
248+ CannotApplyFunction{} -> "CannotApplyFunction"
233− TypeSynonymInstance -> "TypeSynonymInstance"
249+ TypeSynonymInstance -> "TypeSynonymInstance"
234− (OrphanInstance _ _ _) -> "OrphanInstance"
250+ OrphanInstance{} -> "OrphanInstance"
235− InvalidNewtype -> "InvalidNewtype"
251+ InvalidNewtype -> "InvalidNewtype"
236− (InvalidInstanceHead _) -> "InvalidInstanceHead"
252+ InvalidInstanceHead{} -> "InvalidInstanceHead"
237− (TransitiveExportError _ _) -> "TransitiveExportError"
253+ TransitiveExportError{} -> "TransitiveExportError"
238− (ShadowedName _) -> "ShadowedName"
254+ ShadowedName{} -> "ShadowedName"
239− (WildcardInferredType _) -> "WildcardInferredType"
255+ WildcardInferredType{} -> "WildcardInferredType"
240− (NotExhaustivePattern _ _) -> "NotExhaustivePattern"
256+ NotExhaustivePattern{} -> "NotExhaustivePattern"
241− (OverlappingPattern _ _) -> "OverlappingPattern"
257+ OverlappingPattern{} -> "OverlappingPattern"
242− (ClassOperator _ _) -> "ClassOperator"
258+ ClassOperator{} -> "ClassOperator"
243
259
244-- |
260-- |
245-- A stack trace for an error
261-- A stack trace for an error
@@ -451,6 +467,22 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
451 line $ "Unknown type constructor " ++ show name
467 line $ "Unknown type constructor " ++ show name
452 goSimple (UnknownDataConstructor dc tc) =
468 goSimple (UnknownDataConstructor dc tc) =
453 line $ "Unknown data constructor " ++ show dc ++ foldMap ((" for type constructor " ++) . show) tc
469 line $ "Unknown data constructor " ++ show dc ++ foldMap ((" for type constructor " ++) . show) tc
470+ goSimple (UnknownImportType mn name) =
471+ line $ "Module " ++ show mn ++ " does not export type " ++ show name
472+ goSimple (UnknownExportType name) =
473+ line $ "Cannot export unknown type " ++ show name
474+ goSimple (UnknownImportTypeClass mn name) =
475+ line $ "Module " ++ show mn ++ " does not export type class " ++ show name
476+ goSimple (UnknownExportTypeClass name) =
477+ line $ "Cannot export unknown type class " ++ show name
478+ goSimple (UnknownImportValue mn name) =
479+ line $ "Module " ++ show mn ++ " does not export value " ++ show name
480+ goSimple (UnknownExportValue name) =
481+ line $ "Cannot export unknown value " ++ show name
482+ goSimple (UnknownImportDataConstructor mn tcon dcon) =
483+ line $ "Module " ++ show mn ++ " does not export data constructor " ++ show dcon ++ " for type " ++ show tcon
484+ goSimple (UnknownExportDataConstructor tcon dcon) =
485+ line $ "Cannot export data constructor " ++ show dcon ++ " for type " ++ show tcon ++ " as it has not been declared"
454 goSimple (ConflictingImport nm mn) =
486 goSimple (ConflictingImport nm mn) =
455 line $ "Cannot declare " ++ show nm ++ " since another declaration of that name was imported from " ++ show mn
487 line $ "Cannot declare " ++ show nm ++ " since another declaration of that name was imported from " ++ show mn
456 goSimple (ConflictingImports nm m1 m2) =
488 goSimple (ConflictingImports nm m1 m2) =
src/Language/PureScript/Sugar/Names.hs+14−14
@@ -428,7 +428,7 @@ filterExports mn exps env = do
428 filterTypes :: [(ProperName, [ProperName])] -> [(ProperName, [ProperName])] -> DeclarationRef -> m [(ProperName, [ProperName])]
428 filterTypes :: [(ProperName, [ProperName])] -> [(ProperName, [ProperName])] -> DeclarationRef -> m [(ProperName, [ProperName])]
429 filterTypes expTys result (PositionedDeclarationRef pos _ r) = rethrowWithPosition pos $ filterTypes expTys result r
429 filterTypes expTys result (PositionedDeclarationRef pos _ r) = rethrowWithPosition pos $ filterTypes expTys result r
430 filterTypes expTys result (TypeRef name expDcons) = do
430 filterTypes expTys result (TypeRef name expDcons) = do
431− dcons <- maybe (throwError . errorMessage . UnknownType $ Qualified (Just mn) name) return $ name `lookup` expTys
431+ dcons <- maybe (throwError . errorMessage . UnknownExportType $ name) return $ name `lookup` expTys
432 dcons' <- maybe (return dcons) (foldM (filterDcons name dcons) []) expDcons
432 dcons' <- maybe (return dcons) (foldM (filterDcons name dcons) []) expDcons
433 return $ (name, dcons') : result
433 return $ (name, dcons') : result
434 filterTypes _ result _ = return result
434 filterTypes _ result _ = return result
@@ -438,7 +438,7 @@ filterExports mn exps env = do
438 filterDcons tcon exps' result name =
438 filterDcons tcon exps' result name =
439 if name `elem` exps'
439 if name `elem` exps'
440 then return $ name : result
440 then return $ name : result
441− else throwError . errorMessage $ UnknownDataConstructor (Qualified (Just mn) name) (Just (Qualified (Just mn) tcon))
441+ else throwError . errorMessage $ UnknownExportDataConstructor tcon name
442
442
443 -- Ensure the exported classes exist in the module and add them to the set of exports
443 -- Ensure the exported classes exist in the module and add them to the set of exports
444 filterClasses :: [ProperName] -> [ProperName] -> DeclarationRef -> m [ProperName]
444 filterClasses :: [ProperName] -> [ProperName] -> DeclarationRef -> m [ProperName]
@@ -446,7 +446,7 @@ filterExports mn exps env = do
446 filterClasses exps' result (TypeClassRef name) =
446 filterClasses exps' result (TypeClassRef name) =
447 if name `elem` exps'
447 if name `elem` exps'
448 then return $ name : result
448 then return $ name : result
449− else throwError . errorMessage . UnknownTypeClass $ Qualified (Just mn) name
449+ else throwError . errorMessage . UnknownExportTypeClass $ name
450 filterClasses _ result _ = return result
450 filterClasses _ result _ = return result
451
451
452 -- Ensure the exported values exist in the module and add them to the set of exports
452 -- Ensure the exported values exist in the module and add them to the set of exports
@@ -455,7 +455,7 @@ filterExports mn exps env = do
455 filterValues exps' result (ValueRef name) =
455 filterValues exps' result (ValueRef name) =
456 if name `elem` exps'
456 if name `elem` exps'
457 then return $ name : result
457 then return $ name : result
458− else throwError . errorMessage . UnknownValue $ Qualified (Just mn) name
458+ else throwError . errorMessage . UnknownExportValue $ name
459 filterValues _ result _ = return result
459 filterValues _ result _ = return result
460
460
461 -- Add the exported modules to the set of exports
461 -- Add the exported modules to the set of exports
@@ -547,7 +547,7 @@ resolveImport currentModule importModule exps imps impQual =
547 importExplicit imp (TypeRef name dctors) = do
547 importExplicit imp (TypeRef name dctors) = do
548 types' <- updateImports (importedTypes imp) name
548 types' <- updateImports (importedTypes imp) name
549 let allDctors = allExportedDataConstructors name
549 let allDctors = allExportedDataConstructors name
550− dctors' <- maybe (return allDctors) (mapM $ checkDctorExists allDctors) dctors
550+ dctors' <- maybe (return allDctors) (mapM $ (checkDctorExists name) allDctors) dctors
551 dctors'' <- foldM updateImports (importedDataConstructors imp) dctors'
551 dctors'' <- foldM updateImports (importedDataConstructors imp) dctors'
552 return $ imp { importedTypes = types', importedDataConstructors = dctors'' }
552 return $ imp { importedTypes = types', importedDataConstructors = dctors'' }
553 importExplicit imp (TypeClassRef name) = do
553 importExplicit imp (TypeClassRef name) = do
@@ -562,16 +562,16 @@ resolveImport currentModule importModule exps imps impQual =
562 check (PositionedDeclarationRef pos _ r) =
562 check (PositionedDeclarationRef pos _ r) =
563 rethrowWithPosition pos $ check r
563 rethrowWithPosition pos $ check r
564 check ref@(ValueRef name) =
564 check ref@(ValueRef name) =
565− checkImportExists UnknownValue values name >> return ref
565+ checkImportExists UnknownImportValue values name >> return ref
566 check ref@(TypeRef name dctors) = do
566 check ref@(TypeRef name dctors) = do
567− _ <- checkImportExists UnknownType availableTypes name
567+ _ <- checkImportExists UnknownImportType availableTypes name
568 let allDctors = allExportedDataConstructors name
568 let allDctors = allExportedDataConstructors name
569− _ <- maybe (return allDctors) (mapM $ checkDctorExists allDctors) dctors
569+ _ <- maybe (return allDctors) (mapM $ (checkDctorExists name) allDctors) dctors
570 return ref
570 return ref
571 check ref@(TypeClassRef name) =
571 check ref@(TypeClassRef name) =
572− checkImportExists UnknownTypeClass classes name >> return ref
572+ checkImportExists UnknownImportTypeClass classes name >> return ref
573 check ref@(ModuleRef name) =
573 check ref@(ModuleRef name) =
574− checkImportExists (UnknownModule . (\(Qualified _ m) -> m)) (exportedModules exps) name >> return ref
574+ checkImportExists (const UnknownModule) (exportedModules exps) name >> return ref
575 check _ = error "Invalid argument to checkRefIsValid"
575 check _ = error "Invalid argument to checkRefIsValid"
576
576
577 -- Find all exported data constructors for a given type
577 -- Find all exported data constructors for a given type
@@ -596,15 +596,15 @@ resolveImport currentModule importModule exps imps impQual =
596
596
597 -- Ensure that an explicitly imported data constructor exists for the type it is being imported
597 -- Ensure that an explicitly imported data constructor exists for the type it is being imported
598 -- from
598 -- from
599− checkDctorExists :: [ProperName] -> ProperName -> m ProperName
599+ checkDctorExists :: ProperName -> [ProperName] -> ProperName -> m ProperName
600− checkDctorExists = checkImportExists (flip UnknownDataConstructor Nothing)
600+ checkDctorExists tcon = checkImportExists (flip UnknownImportDataConstructor tcon)
601
601
602 -- Check that an explicitly imported item exists in the module it is being imported from
602 -- Check that an explicitly imported item exists in the module it is being imported from
603− checkImportExists :: (Eq a, Show a) => (Qualified a -> SimpleErrorMessage) -> [a] -> a -> m a
603+ checkImportExists :: (Eq a, Show a) => (ModuleName -> a -> SimpleErrorMessage) -> [a] -> a -> m a
604 checkImportExists unknown exports item =
604 checkImportExists unknown exports item =
605 if item `elem` exports
605 if item `elem` exports
606 then return item
606 then return item
607− else throwError . errorMessage . unknown $ Qualified (Just importModule) item
607+ else throwError . errorMessage $ unknown importModule item
608
608
609-- |
609-- |
610-- Raises an error for when there is more than one definition for something.
610-- Raises an error for when there is more than one definition for something.