git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge branch 'master' into pure11-0.9
commit95fdf2e17af11dae27bbbf5f1ac9ce312b44c6ce authorAndy Arvanitis <andyarvanitis@gmail.com> dateSun 14 Aug 2016, 13:07 (10 years ago) parentfebbf0a9b34d87
59 files changed+518−419
.gitignore+1 CONTRIBUTORS.md+6−4 examples/passing/2252.purs+15 purescript.cabal+8−7 src/Language/PureScript/AST/Binders.hs+1−1 src/Language/PureScript/AST/Declarations.hs+159−18 src/Language/PureScript/AST/Literals.hs+1−1 src/Language/PureScript/AST/Operators.hs+2−2 src/Language/PureScript/AST/SourcePos.hs+2−2 src/Language/PureScript/AST/Traversals.hs+1−1 src/Language/PureScript/Bundle.hs+3−3 src/Language/PureScript/CodeGen/JS.hs+11−6 src/Language/PureScript/CodeGen/JS/AST.hs+3−3 src/Language/PureScript/CodeGen/JS/Common.hs+1−1 src/Language/PureScript/Comments.hs+1−1 src/Language/PureScript/CoreFn/Binders.hs+1−1 src/Language/PureScript/CoreFn/Expr.hs+3−3 src/Language/PureScript/CoreFn/Meta.hs+2−2 src/Language/PureScript/CoreFn/Module.hs+1−1 src/Language/PureScript/Docs/AsMarkdown.hs+1−1 src/Language/PureScript/Docs/Convert.hs+1−1 src/Language/PureScript/Environment.hs+7−8 src/Language/PureScript/Errors.hs+58−164 src/Language/PureScript/Externs.hs+7−7 src/Language/PureScript/Ide/Command.hs−1 src/Language/PureScript/Ide/Externs.hs−1 src/Language/PureScript/Ide/Imports.hs−1 src/Language/PureScript/Ide/Pursuit.hs+2−2 src/Language/PureScript/Ide/Rebuild.hs+2−2 src/Language/PureScript/Ide/SourceFile.hs−1 src/Language/PureScript/Ide/State.hs−1 src/Language/PureScript/Ide/Types.hs−1 src/Language/PureScript/Ide/Util.hs+1−1 src/Language/PureScript/Interactive.hs+1−1 src/Language/PureScript/Interactive/Completion.hs+1−1 src/Language/PureScript/Interactive/Printer.hs+8−5 src/Language/PureScript/Kinds.hs+1−1 src/Language/PureScript/Make.hs+4−3 src/Language/PureScript/Names.hs+5−5 src/Language/PureScript/Parser/Lexer.hs+1−1 src/Language/PureScript/Pretty/Values.hs+1−3 src/Language/PureScript/Publish.hs+2−2 src/Language/PureScript/Sugar/Names/Env.hs+4−4 src/Language/PureScript/Sugar/Operators.hs+2−2 src/Language/PureScript/Sugar/TypeClasses.hs+1−2 src/Language/PureScript/TypeChecker.hs+5−5 src/Language/PureScript/TypeChecker/Entailment.hs+21−19 src/Language/PureScript/TypeChecker/Kinds.hs+2−2 src/Language/PureScript/TypeChecker/Monad.hs+68−27 src/Language/PureScript/TypeChecker/Subsumption.hs+4−3 src/Language/PureScript/TypeChecker/Types.hs+60−66 src/Language/PureScript/TypeChecker/Unify.hs+9−5 src/Language/PureScript/TypeClassDictionaries.hs+2−2 src/Language/PureScript/Types.hs+4−4 stack-ghc-8.0.yaml+1−1 stack.yaml+7−3 tests/Language/PureScript/Ide/ImportsSpec.hs+1−1 tests/Language/PureScript/Ide/Integration.hs+1−1 tests/TestPscPublish.hs+1−1
.gitignore+1
@@ -17,3 +17,4 @@ tmp/
1717output
1818examples/docs/docs/
1919core-tests/full-core-docs.md
20+.psc-ide-port
CONTRIBUTORS.md+6−4
@@ -12,7 +12,9 @@ This file lists the contributors to the PureScript compiler project, and the ter
1212- [@bagl](https://github.com/bagl) (Petr Vapenka) My existing contributions and all future contributions until further notice are Copyright Petr Vapenka, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
1313- [@balajirrao](https://github.com/balajirrao) (Balaji Rao) - My existing contributions and all future contributions until further notice are Copyright Balaji Rao, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
1414- [@bergmark](https://github.com/bergmark) (Adam Bergmark) - My existing contributions and all future contributions until further notice are Copyright Adam Bergmark, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
15+- [@bmjames](https://github.com/bmjames) (Ben James) My existing contributions and all future contributions until further notice are Copyright Ben James, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
1516- [@Bogdanp](https://github.com/Bogdanp) (Bogdan Paul Popa) My existing contributions and all future contributions until further notice are Copyright Bogdan Paul Popa, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
17+- [@bsermons](https://github.com/bsermons) (Brian Sermons) My existing contributions and all future contributions until further notice are Copyright Brian Sermons, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
1618- [@cdepillabout](https://github.com/cdepillabout) (Dennis Gosnell) My existing contributions and all future contributions until further notice are Copyright Dennis Gosnell, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
1719- [@chrissmoak](https://github.com/chrissmoak) (Chris Smoak) My existing contributions to the PureScript compiler and all future contributions to the PureScript compiler until further notice, are Copyright Chris Smoak, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
1820- [@codedmart](https://github.com/codedmart) (Brandon Martin) My existing contributions and all future contributions until further notice are Copyright Brandon Martin, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
@@ -25,8 +27,10 @@ This file lists the contributors to the PureScript compiler project, and the ter
2527- [@erdeszt](https://github.com/erdeszt) (Tibor Erdesz) My existing contributions and all future contributions until further notice are Copyright Tibor Erdesz, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
2628- [@etrepum](https://github.com/etrepum) (Bob Ippolito) My existing contributions and all future contributions until further notice are Copyright Bob Ippolito, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
2729- [@faineance](https://github.com/faineance) My existing contributions and all future contributions until further notice are Copyright faineance, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
30+- [@felixSchl](https://github.com/felixSchl) (Felix Schlitter) My existing contributions and all future contributions until further notice are Copyright Felix Schlitter, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
2831- [@garyb](https://github.com/garyb) (Gary Burgess) My existing contributions and all future contributions until further notice are Copyright Gary Burgess, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
2932- [@hdgarrood](https://github.com/hdgarrood) (Harry Garrood) My existing contributions and all future contributions until further notice are Copyright Harry Garrood, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
33+- [@ilovezfs](https://github.com/ilovezfs) - My existing contributions and all future contributions until further notice are Copyright ilovezfs, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license
3034- [@izgzhen](https://github.com/izgzhen) (Zhen Zhang) My existing contributions and all future contributions until further notice are Copyright Zhen Zhang, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
3135- [@jacereda](https://github.com/jacereda) (Jorge Acereda) My existing contributions and all future contributions until further notice are Copyright Jorge Acereda, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
3236- [@japesinator](https://github.com/japesinator) (JP Smith) My existing contributions and all future contributions until further notice are Copyright JP Smith, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
@@ -35,6 +39,7 @@ This file lists the contributors to the PureScript compiler project, and the ter
3539- [@kRITZCREEK](https://github.com/kRITZCREEK) (Christoph Hegemann) - My existing contributions and all future contributions until further notice are Copyright Christoph Hegemann, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
3640- [@L8D](https://github.com/L8D) (Tenor Biel) My existing contributions and all future contributions until further notice are Copyright Tenor Biel, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
3741- [@leighman](http://github.com/leighman) (Jack Leigh) My existing contributions and all future contributions until further notice are Copyright Jack Leigh, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
42+- [@LiamGoodacre](https://github.com/LiamGoodacre) (Liam Goodacre) My existing contributions and all future contributions until further notice are Copyright Liam Goodacre, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
3843- [@lukerandall](https://github.com/lukerandall) (Luke Randall) My existing contributions and all future contributions until further notice are Copyright Luke Randall, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
3944- [@mgmeier](https://github.com/mgmeier) (Michael Karg) My existing contributions and all future contributions until further notice are Copyright Michael Gilliland, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
4045- [@michaelficarra](https://github.com/michaelficarra) (Michael Ficarra) My existing contributions and all future contributions until further notice are Copyright Michael Ficarra, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
@@ -58,6 +63,7 @@ This file lists the contributors to the PureScript compiler project, and the ter
5863- [@puffnfresh](https://github.com/puffnfresh) (Brian McKenna) All contributions I made during June 2015 were during employment at [SlamData, Inc.](#companies) who owns the copyright. I assign copyright of all my personal contributions before June 2015 to the owners of the PureScript compiler.
5964- [@robdaemon](https://github.com/robdaemon) (Robert Roland) My existing contributions and all future contributions until further notice are Copyright Robert Roland, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
6065- [@RossMeikleham](https://github.com/RossMeikleham) (Ross Meikleham) My existing contributions and all future contributions until further notice are Copyright Ross Meikleham, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
66+- [@rvion](https://github.com/rvion) (Rémi Vion) My existing contributions and all future contributions until further notice are Copyright Rémi Vion, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
6167- [@sebastiaanvisser](https://github.com/sebastiaanvisser) (Sebastiaan Visser) - My existing contributions and all future contributions until further notice are Copyright Sebastiaan Visser, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
6268- [@senju](https://github.com/senju) - My existing contributions and all future contributions until further notice are Copyright senju, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
6369- [@sharkdp](https://github.com/sharkdp) (David Peter) My existing contributions and all future contributions until further notice are Copyright David Peter, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
@@ -69,10 +75,6 @@ This file lists the contributors to the PureScript compiler project, and the ter
6975- [@utkarshkukreti](https://github.com/utkarshkukreti) (Utkarsh Kukreti) My existing contributions and all future contributions until further notice are Copyright Utkarsh Kukreti, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
7076- [@vkorablin](https://github.com/vkorablin) (Vladimir Korablin) - My existing contributions and all future contributions until further notice are Copyright Vladimir Korablin, and are licensed to the owners and users of the PureScript compiler project under the terms of the MIT license.
7177- [@zudov](https://github.com/zudov) (Konstantin Zudov) My existing contributions and all future contributions until further notice are Copyright Konstantin Zudov, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
72−- [@LiamGoodacre](https://github.com/LiamGoodacre) (Liam Goodacre) My existing contributions and all future contributions until further notice are Copyright Liam Goodacre, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
73−- [@bsermons](https://github.com/bsermons) (Brian Sermons) My existing contributions and all future contributions until further notice are Copyright Brian Sermons, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
74−- [@bmjames](https://github.com/bmjames) (Ben James) My existing contributions and all future contributions until further notice are Copyright Ben James, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
75−- - [@felixSchl](https://github.com/felixSchl) (Felix Schlitter) My existing contributions and all future contributions until further notice are Copyright Felix Schlitter, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
7678
7779### Companies
7880
examples/passing/2252.pursnew file+15
@@ -0,0 +1,15 @@
1+module Main where
2+
3+import Control.Monad.Eff.Console (log)
4+
5+data T a = T
6+
7+ti :: T Int
8+ti = T
9+
10+t :: forall a. T a
11+t = T
12+
13+xs = [ti, t, t]
14+
15+main = log "Done"
purescript.cabal+8−7
@@ -1,5 +1,5 @@
11name: purescript
2−version: 0.9.2
2+version: 0.9.3
33cabal-version: >=1.8
44build-type: Simple
55license: MIT
@@ -101,7 +101,7 @@ source-repository head
101101
102102library
103103 build-depends: base >=4.8 && <5,
104− aeson >= 0.8 && < 0.12,
104+ aeson >= 0.8 && < 1.1,
105105 aeson-better-errors >= 0.8,
106106 ansi-terminal >= 0.6.2 && < 0.7,
107107 base-compat >=0.6.0,
@@ -117,6 +117,7 @@ library
117117 fsnotify >= 0.2.1,
118118 Glob >= 0.7 && < 0.8,
119119 haskeline >= 0.7.0.0,
120+ http-client >= 0.4.30 && <0.5,
120121 http-types -any,
121122 language-javascript == 0.6.*,
122123 lifted-base >= 0.2.3 && < 0.2.4,
@@ -129,7 +130,7 @@ library
129130 pipes >= 4.0.0 && < 4.3.0,
130131 pipes-http -any,
131132 process >= 1.2.0 && < 1.5,
132− protolude >= 0.1.5,
133+ protolude >= 0.1.6,
133134 regex-tdfa -any,
134135 safe >= 0.3.9 && < 0.4,
135136 semigroups >= 0.16.2 && < 0.19,
@@ -330,7 +331,7 @@ library
330331executable psc
331332 build-depends: base >=4 && <5,
332333 purescript -any,
333− aeson >= 0.8 && < 0.12,
334+ aeson >= 0.8 && < 1.1,
334335 ansi-terminal >= 0.6.2 && < 0.7,
335336 base-compat >=0.6.0,
336337 bytestring -any,
@@ -455,7 +456,7 @@ executable psc-ide-server
455456 other-modules: Paths_purescript
456457 other-extensions:
457458 build-depends: base >=4 && <5,
458− aeson >= 0.8 && < 0.12,
459+ aeson >= 0.8 && < 1.1,
459460 bytestring -any,
460461 purescript -any,
461462 base-compat >=0.6.0,
@@ -465,7 +466,7 @@ executable psc-ide-server
465466 mtl -any,
466467 network -any,
467468 optparse-applicative >= 0.12.1,
468− protolude >= 0.1.5,
469+ protolude >= 0.1.6,
469470 stm -any,
470471 text -any,
471472 transformers -any,
@@ -533,7 +534,7 @@ test-suite tests
533534 optparse-applicative -any,
534535 parsec -any,
535536 process -any,
536− protolude >= 0.1.5,
537+ protolude >= 0.1.6,
537538 silently -any,
538539 stm -any,
539540 text -any,
src/Language/PureScript/AST/Binders.hs+1−1
@@ -61,7 +61,7 @@ data Binder
6161 -- A binder with a type annotation
6262 --
6363 | TypedBinder Type Binder
64− deriving (Show, Read, Eq)
64+ deriving (Show, Eq)
6565
6666-- |
6767-- Collect all names introduced in binders in an expression
src/Language/PureScript/AST/Declarations.hs+159−18
@@ -22,6 +22,148 @@ import Language.PureScript.Kinds
2222import Language.PureScript.TypeClassDictionaries
2323import Language.PureScript.Comments
2424import Language.PureScript.Environment
25+import qualified Language.PureScript.Bundle as Bundle
26+
27+import qualified Text.Parsec as P
28+
29+-- | A map of locally-bound names in scope.
30+type Context = [(Ident, Type)]
31+
32+-- | A type of error messages
33+data SimpleErrorMessage
34+ = ErrorParsingFFIModule FilePath (Maybe Bundle.ErrorMessage)
35+ | ErrorParsingModule P.ParseError
36+ | MissingFFIModule ModuleName
37+ | MultipleFFIModules ModuleName [FilePath]
38+ | UnnecessaryFFIModule ModuleName FilePath
39+ | MissingFFIImplementations ModuleName [Ident]
40+ | UnusedFFIImplementations ModuleName [Ident]
41+ | InvalidFFIIdentifier ModuleName String
42+ | CannotGetFileInfo FilePath
43+ | CannotReadFile FilePath
44+ | CannotWriteFile FilePath
45+ | InfiniteType Type
46+ | InfiniteKind Kind
47+ | MultipleValueOpFixities (OpName 'ValueOpName)
48+ | MultipleTypeOpFixities (OpName 'TypeOpName)
49+ | OrphanTypeDeclaration Ident
50+ | RedefinedModule ModuleName [SourceSpan]
51+ | RedefinedIdent Ident
52+ | OverlappingNamesInLet
53+ | UnknownName (Qualified Name)
54+ | UnknownImport ModuleName Name
55+ | UnknownImportDataConstructor ModuleName (ProperName 'TypeName) (ProperName 'ConstructorName)
56+ | UnknownExport Name
57+ | UnknownExportDataConstructor (ProperName 'TypeName) (ProperName 'ConstructorName)
58+ | ScopeConflict Name [ModuleName]
59+ | ScopeShadowing Name (Maybe ModuleName) [ModuleName]
60+ | DeclConflict Name Name
61+ | ExportConflict (Qualified Name) (Qualified Name)
62+ | DuplicateModuleName ModuleName
63+ | DuplicateTypeArgument String
64+ | InvalidDoBind
65+ | InvalidDoLet
66+ | CycleInDeclaration Ident
67+ | CycleInTypeSynonym (Maybe (ProperName 'TypeName))
68+ | CycleInModules [ModuleName]
69+ | NameIsUndefined Ident
70+ | UndefinedTypeVariable (ProperName 'TypeName)
71+ | PartiallyAppliedSynonym (Qualified (ProperName 'TypeName))
72+ | EscapedSkolem (Maybe Expr)
73+ | TypesDoNotUnify Type Type
74+ | KindsDoNotUnify Kind Kind
75+ | ConstrainedTypeUnified Type Type
76+ | OverlappingInstances (Qualified (ProperName 'ClassName)) [Type] [Qualified Ident]
77+ | NoInstanceFound Constraint
78+ | PossiblyInfiniteInstance (Qualified (ProperName 'ClassName)) [Type]
79+ | CannotDerive (Qualified (ProperName 'ClassName)) [Type]
80+ | CannotFindDerivingType (ProperName 'TypeName)
81+ | DuplicateLabel String (Maybe Expr)
82+ | DuplicateValueDeclaration Ident
83+ | ArgListLengthsDiffer Ident
84+ | OverlappingArgNames (Maybe Ident)
85+ | MissingClassMember Ident
86+ | ExtraneousClassMember Ident (Qualified (ProperName 'ClassName))
87+ | ExpectedType Type Kind
88+ | IncorrectConstructorArity (Qualified (ProperName 'ConstructorName))
89+ | ExprDoesNotHaveType Expr Type
90+ | PropertyIsMissing String
91+ | AdditionalProperty String
92+ | CannotApplyFunction Type Expr
93+ | TypeSynonymInstance
94+ | OrphanInstance Ident (Qualified (ProperName 'ClassName)) [Type]
95+ | InvalidNewtype (ProperName 'TypeName)
96+ | InvalidInstanceHead Type
97+ | TransitiveExportError DeclarationRef [DeclarationRef]
98+ | TransitiveDctorExportError DeclarationRef (ProperName 'ConstructorName)
99+ | ShadowedName Ident
100+ | ShadowedTypeVar String
101+ | UnusedTypeVar String
102+ | WildcardInferredType Type Context
103+ | HoleInferredType String Type Context
104+ | MissingTypeDeclaration Ident Type
105+ | OverlappingPattern [[Binder]] Bool
106+ | IncompleteExhaustivityCheck
107+ | MisleadingEmptyTypeImport ModuleName (ProperName 'TypeName)
108+ | ImportHidingModule ModuleName
109+ | UnusedImport ModuleName
110+ | UnusedExplicitImport ModuleName [String] (Maybe ModuleName) [DeclarationRef]
111+ | UnusedDctorImport (ProperName 'TypeName)
112+ | UnusedDctorExplicitImport (ProperName 'TypeName) [ProperName 'ConstructorName]
113+ | DuplicateSelectiveImport ModuleName
114+ | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
115+ | DuplicateImportRef Name
116+ | DuplicateExportRef Name
117+ | IntOutOfRange Integer String Integer Integer
118+ | ImplicitQualifiedImport ModuleName ModuleName [DeclarationRef]
119+ | ImplicitImport ModuleName [DeclarationRef]
120+ | HidingImport ModuleName [DeclarationRef]
121+ | CaseBinderLengthDiffers Int [Binder]
122+ | IncorrectAnonymousArgument
123+ | InvalidOperatorInBinder (Qualified (OpName 'ValueOpName)) (Qualified Ident)
124+ | DeprecatedRequirePath
125+ | CannotGeneralizeRecursiveFunction Ident Type
126+ deriving (Show)
127+
128+-- | Error message hints, providing more detailed information about failure.
129+data ErrorMessageHint
130+ = ErrorUnifyingTypes Type Type
131+ | ErrorInExpression Expr
132+ | ErrorInModule ModuleName
133+ | ErrorInInstance (Qualified (ProperName 'ClassName)) [Type]
134+ | ErrorInSubsumption Type Type
135+ | ErrorCheckingAccessor Expr String
136+ | ErrorCheckingType Expr Type
137+ | ErrorCheckingKind Type
138+ | ErrorCheckingGuard
139+ | ErrorInferringType Expr
140+ | ErrorInApplication Expr Type Expr
141+ | ErrorInDataConstructor (ProperName 'ConstructorName)
142+ | ErrorInTypeConstructor (ProperName 'TypeName)
143+ | ErrorInBindingGroup [Ident]
144+ | ErrorInDataBindingGroup
145+ | ErrorInTypeSynonym (ProperName 'TypeName)
146+ | ErrorInValueDeclaration Ident
147+ | ErrorInTypeDeclaration Ident
148+ | ErrorInForeignImport Ident
149+ | ErrorSolvingConstraint Constraint
150+ | PositionedError SourceSpan
151+ deriving (Show)
152+
153+-- | Categories of hints
154+data HintCategory
155+ = ExprHint
156+ | KindHint
157+ | CheckHint
158+ | PositionHint
159+ | SolverHint
160+ | OtherHint
161+ deriving (Show, Eq)
162+
163+data ErrorMessage = ErrorMessage
164+ [ErrorMessageHint]
165+ SimpleErrorMessage
166+ deriving (Show)
25167
26168-- |
27169-- A module declaration, consisting of comments about the module, a module name,
@@ -29,7 +171,7 @@ import Language.PureScript.Environment
29171-- explicitly exported. If the export list is Nothing, everything is exported.
30172--
31173data Module = Module SourceSpan [Comment] ModuleName [Declaration] (Maybe [DeclarationRef])
32− deriving (Show, Read)
174+ deriving (Show)
33175
34176-- | Return a module's name.
35177getModuleName :: Module -> ModuleName
@@ -88,7 +230,7 @@ data DeclarationRef
88230 -- A declaration reference with source position information
89231 --
90232 | PositionedDeclarationRef SourceSpan [Comment] DeclarationRef
91− deriving (Show, Read)
233+ deriving (Show)
92234
93235instance Eq DeclarationRef where
94236 (TypeRef name dctors) == (TypeRef name' dctors') = name == name' && dctors == dctors'
@@ -149,7 +291,7 @@ data ImportDeclarationType
149291 -- An import with a list of references to hide: `import M hiding (foo)`
150292 --
151293 | Hiding [DeclarationRef]
152− deriving (Eq, Show, Read)
294+ deriving (Eq, Show)
153295
154296isImplicit :: ImportDeclarationType -> Bool
155297isImplicit Implicit = True
@@ -216,15 +358,15 @@ data Declaration
216358 -- A declaration with source position information
217359 --
218360 | PositionedDeclaration SourceSpan [Comment] Declaration
219− deriving (Show, Read)
361+ deriving (Show)
220362
221363data ValueFixity = ValueFixity Fixity (Qualified (Either Ident (ProperName 'ConstructorName))) (OpName 'ValueOpName)
222− deriving (Eq, Ord, Show, Read)
364+ deriving (Eq, Ord, Show)
223365
224366data TypeFixity = TypeFixity Fixity (Qualified (ProperName 'TypeName)) (OpName 'TypeOpName)
225− deriving (Eq, Ord, Show, Read)
367+ deriving (Eq, Ord, Show)
226368
227−pattern ValueFixityDeclaration :: Fixity -> Qualified (Either Ident (ProperName 'ConstructorName)) -> OpName 'ValueOpName -> Declaration
369+pattern ValueFixityDeclaration :: Fixity -> Qualified (Either Ident (ProperName 'ConstructorName)) -> OpName 'ValueOpName -> Declaration
228370pattern ValueFixityDeclaration fixity name op = FixityDeclaration (Left (ValueFixity fixity name op))
229371
230372pattern TypeFixityDeclaration :: Fixity -> Qualified (ProperName 'TypeName) -> OpName 'TypeOpName -> Declaration
@@ -236,7 +378,7 @@ data TypeInstanceBody
236378 = DerivedInstance
237379 -- | This is a regular (explicit) instance
238380 | ExplicitInstance [Declaration]
239− deriving (Show, Read)
381+ deriving (Show)
240382
241383mapTypeInstanceBody :: ([Declaration] -> [Declaration]) -> TypeInstanceBody -> TypeInstanceBody
242384mapTypeInstanceBody f = runIdentity . traverseTypeInstanceBody (Identity . f)
@@ -355,12 +497,9 @@ data Expr
355497 --
356498 | Parens Expr
357499 -- |
358− -- A record property getter (e.g. `_.x`). This will be removed during
359− -- desugaring and expanded into a lambda that reads a property from a record.
360− --
361− | ObjectGetter String
362− -- |
363− -- An record property accessor expression
500+ -- An record property accessor expression (e.g. `obj.x` or `_.x`).
501+ -- Anonymous arguments will be removed during desugaring and expanded
502+ -- into a lambda that reads a property from a record.
364503 --
365504 | Accessor String Expr
366505 -- |
@@ -421,7 +560,9 @@ data Expr
421560 -- at superclass implementations when searching for a dictionary, the type class name and
422561 -- instance type, and the type class dictionaries in scope.
423562 --
424− | TypeClassDictionary Constraint (M.Map (Maybe ModuleName) (M.Map (Qualified (ProperName 'ClassName)) (M.Map (Qualified Ident) TypeClassDictionaryInScope)))
563+ | TypeClassDictionary Constraint
564+ (M.Map (Maybe ModuleName) (M.Map (Qualified (ProperName 'ClassName)) (M.Map (Qualified Ident) TypeClassDictionaryInScope)))
565+ [ErrorMessageHint]
425566 -- |
426567 -- A typeclass dictionary accessor, the implementation is left unspecified until CoreFn desugaring.
427568 --
@@ -442,7 +583,7 @@ data Expr
442583 -- A value with source position information
443584 --
444585 | PositionedValue SourceSpan [Comment] Expr
445− deriving (Show, Read)
586+ deriving (Show)
446587
447588-- |
448589-- An alternative in a case statement
@@ -456,7 +597,7 @@ data CaseAlternative = CaseAlternative
456597 -- The result expression or a collect of guarded expressions
457598 --
458599 , caseAlternativeResult :: Either [(Guard, Expr)] Expr
459− } deriving (Show, Read)
600+ } deriving (Show)
460601
461602-- |
462603-- A statement in a do-notation block
@@ -478,7 +619,7 @@ data DoNotationElement
478619 -- A do notation element with source position information
479620 --
480621 | PositionedDoNotationElement SourceSpan [Comment] DoNotationElement
481− deriving (Show, Read)
622+ deriving (Show)
482623
483624$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''DeclarationRef)
484625$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ImportDeclarationType)
src/Language/PureScript/AST/Literals.hs+1−1
@@ -34,4 +34,4 @@ data Literal a
3434 -- An object literal
3535 --
3636 | ObjectLiteral [(String, a)]
37− deriving (Eq, Ord, Show, Read, Functor)
37+ deriving (Eq, Ord, Show, Functor)
src/Language/PureScript/AST/Operators.hs+2−2
@@ -21,7 +21,7 @@ type Precedence = Integer
2121-- Associativity for infix operators
2222--
2323data Associativity = Infixl | Infixr | Infix
24− deriving (Show, Read, Eq, Ord)
24+ deriving (Show, Eq, Ord)
2525
2626showAssoc :: Associativity -> String
2727showAssoc Infixl = "infixl"
@@ -44,7 +44,7 @@ instance A.FromJSON Associativity where
4444-- Fixity data for infix operators
4545--
4646data Fixity = Fixity Associativity Precedence
47− deriving (Show, Read, Eq, Ord)
47+ deriving (Show, Eq, Ord)
4848
4949instance A.ToJSON Fixity where
5050 toJSON (Fixity associativity precedence) =
src/Language/PureScript/AST/SourcePos.hs+2−2
@@ -22,7 +22,7 @@ data SourcePos = SourcePos
2222 -- Column number
2323 --
2424 , sourcePosColumn :: Int
25− } deriving (Show, Read, Eq, Ord)
25+ } deriving (Show, Eq, Ord)
2626
2727displaySourcePos :: SourcePos -> String
2828displaySourcePos sp =
@@ -50,7 +50,7 @@ data SourceSpan = SourceSpan
5050 -- End of the span
5151 --
5252 , spanEnd :: SourcePos
53− } deriving (Show, Read, Eq, Ord)
53+ } deriving (Show, Eq, Ord)
5454
5555displayStartEndPos :: SourceSpan -> String
5656displayStartEndPos sp =
src/Language/PureScript/AST/Traversals.hs+1−1
@@ -582,7 +582,7 @@ accumTypes f = everythingOnValues mappend forDecls forValues (const mempty) (con
582582 forDecls (TypeDeclaration _ ty) = f ty
583583 forDecls _ = mempty
584584
585− forValues (TypeClassDictionary c _) = mconcat (map f (constraintArgs c))
585+ forValues (TypeClassDictionary c _ _) = mconcat (map f (constraintArgs c))
586586 forValues (SuperClassDictionary _ tys) = mconcat (map f tys)
587587 forValues (TypedValue _ _ ty) = f ty
588588 forValues _ = mempty
src/Language/PureScript/Bundle.hs+3−3
@@ -43,20 +43,20 @@ data ErrorMessage
4343 | UnableToParseModule String
4444 | UnsupportedExport
4545 | ErrorInModule ModuleIdentifier ErrorMessage
46− deriving (Show, Read)
46+ deriving (Show)
4747
4848-- | Modules are either "regular modules" (i.e. those generated by psc) or foreign modules.
4949data ModuleType
5050 = Regular
5151 | Foreign
52− deriving (Show, Read, Eq, Ord)
52+ deriving (Show, Eq, Ord)
5353
5454showModuleType :: ModuleType -> String
5555showModuleType Regular = "Regular"
5656showModuleType Foreign = "Foreign"
5757
5858-- | A module is identified by its module name and its type.
59−data ModuleIdentifier = ModuleIdentifier String ModuleType deriving (Show, Read, Eq, Ord)
59+data ModuleIdentifier = ModuleIdentifier String ModuleType deriving (Show, Eq, Ord)
6060
6161moduleName :: ModuleIdentifier -> String
6262moduleName (ModuleIdentifier name _) = name
src/Language/PureScript/CodeGen/JS.hs+11−6
@@ -27,7 +27,9 @@ import Language.PureScript.CodeGen.JS.Common as Common
2727import Language.PureScript.CodeGen.JS.Optimizer
2828import Language.PureScript.CoreFn
2929import Language.PureScript.Crash
30−import Language.PureScript.Errors
30+import Language.PureScript.Errors (ErrorMessageHint(..), SimpleErrorMessage(..),
31+ MultipleErrors(..), rethrow,
32+ errorMessage, rethrowWithPosition, addHint)
3133import Language.PureScript.Names
3234import Language.PureScript.Options
3335import Language.PureScript.Traversals (sndM)
@@ -280,15 +282,18 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
280282 extendObj obj sts = do
281283 newObj <- freshName
282284 key <- freshName
285+ evaluatedObj <- freshName
283286 let
284287 jsKey = JSVar Nothing key
285288 jsNewObj = JSVar Nothing newObj
286− block = JSBlock Nothing (objAssign:copy:extend ++ [JSReturn Nothing jsNewObj])
289+ jsEvaluatedObj = JSVar Nothing evaluatedObj
290+ block = JSBlock Nothing (evaluate:objAssign:copy:extend ++ [JSReturn Nothing jsNewObj])
291+ evaluate = JSVariableIntroduction Nothing evaluatedObj (Just obj)
287292 objAssign = JSVariableIntroduction Nothing newObj (Just $ JSObjectLiteral Nothing [])
288− copy = JSForIn Nothing key obj $ JSBlock Nothing [JSIfElse Nothing cond assign Nothing]
289− cond = JSApp Nothing (JSAccessor Nothing "hasOwnProperty" obj) [jsKey]
290− assign = JSBlock Nothing [JSAssignment Nothing (JSIndexer Nothing jsKey jsNewObj) (JSIndexer Nothing jsKey obj)]
291− stToAssign (s, js) = JSAssignment Nothing (JSAccessor Nothing s jsNewObj) js
293+ copy = JSForIn Nothing key jsEvaluatedObj $ JSBlock Nothing [JSIfElse Nothing cond assign Nothing]
294+ cond = JSApp Nothing (JSAccessor Nothing "hasOwnProperty" jsEvaluatedObj) [jsKey]
295+ assign = JSBlock Nothing [JSAssignment Nothing (JSIndexer Nothing jsKey jsNewObj) (JSIndexer Nothing jsKey jsEvaluatedObj)]
296+ stToAssign (s, js) = JSAssignment Nothing (accessorString s jsNewObj) js
292297 extend = map stToAssign sts
293298 return $ JSApp Nothing (JSFunction Nothing Nothing [] block) []
294299
src/Language/PureScript/CodeGen/JS/AST.hs+3−3
@@ -35,7 +35,7 @@ data UnaryOperator
3535 -- Constructor
3636 --
3737 | JSNew
38− deriving (Show, Read, Eq)
38+ deriving (Show, Eq)
3939
4040-- |
4141-- Built-in binary operators
@@ -117,7 +117,7 @@ data BinaryOperator
117117 -- Bitwise right shift with zero-fill
118118 --
119119 | ZeroFillShiftRight
120− deriving (Show, Read, Eq)
120+ deriving (Show, Eq)
121121
122122-- |
123123-- Data type for simplified Javascript expressions
@@ -238,7 +238,7 @@ data JS
238238 -- |
239239 -- Commented Javascript
240240 --
241− | JSComment (Maybe SourceSpan) [Comment] JS deriving (Show, Read, Eq)
241+ | JSComment (Maybe SourceSpan) [Comment] JS deriving (Show, Eq)
242242
243243withSourceSpan :: SourceSpan -> JS -> JS
244244withSourceSpan withSpan = go
src/Language/PureScript/CodeGen/JS/Common.hs+1−1
@@ -35,7 +35,7 @@ identToJs (GenIdent _ _) = internalError "GenIdent in identToJs"
3535-- Test if a string is a valid JS identifier without escaping.
3636--
3737identNeedsEscaping :: String -> Bool
38−identNeedsEscaping s = s /= identToJs (Ident s)
38+identNeedsEscaping s = s /= identToJs (Ident s) || null s
3939
4040-- |
4141-- Attempts to find a human-readable name for a symbol, if none has been specified returns the
src/Language/PureScript/Comments.hs+1−1
@@ -12,6 +12,6 @@ import Data.Aeson.TH
1212data Comment
1313 = LineComment String
1414 | BlockComment String
15− deriving (Show, Read, Eq, Ord)
15+ deriving (Show, Eq, Ord)
1616
1717$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''Comment)
src/Language/PureScript/CoreFn/Binders.hs+1−1
@@ -31,7 +31,7 @@ data Binder a
3131 -- |
3232 -- A binder which binds its input to an identifier
3333 --
34− | NamedBinder a Ident (Binder a) deriving (Show, Read, Functor)
34+ | NamedBinder a Ident (Binder a) deriving (Show, Functor)
3535
3636
3737extractBinderAnn :: Binder a -> a
src/Language/PureScript/CoreFn/Expr.hs+3−3
@@ -51,7 +51,7 @@ data Expr a
5151 -- A let binding
5252 --
5353 | Let a [Bind a] (Expr a)
54− deriving (Show, Read, Functor)
54+ deriving (Show, Functor)
5555
5656-- |
5757-- A let or module binding.
@@ -64,7 +64,7 @@ data Bind a
6464 -- |
6565 -- Mutually recursive binding group for several values
6666 --
67− | Rec [((a, Ident), Expr a)] deriving (Show, Read, Functor)
67+ | Rec [((a, Ident), Expr a)] deriving (Show, Functor)
6868
6969-- |
7070-- A guard is just a boolean-valued expression that appears alongside a set of binders
@@ -83,7 +83,7 @@ data CaseAlternative a = CaseAlternative
8383 -- The result expression or a collect of guarded expressions
8484 --
8585 , caseAlternativeResult :: Either [(Guard a, Expr a)] (Expr a)
86− } deriving (Show, Read)
86+ } deriving (Show)
8787
8888instance Functor CaseAlternative where
8989
src/Language/PureScript/CoreFn/Meta.hs+2−2
@@ -26,7 +26,7 @@ data Meta
2626 -- |
2727 -- The contained reference is for a foreign member
2828 --
29− | IsForeign deriving (Show, Read, Eq)
29+ | IsForeign deriving (Show, Eq)
3030
3131-- |
3232-- Data constructor metadata
@@ -39,4 +39,4 @@ data ConstructorType
3939 -- |
4040 -- The constructor is for a type with multiple construcors
4141 --
42− | SumType deriving (Show, Read, Eq)
42+ | SumType deriving (Show, Eq)
src/Language/PureScript/CoreFn/Module.hs+1−1
@@ -17,6 +17,6 @@ data Module a = Module
1717 , moduleExports :: [Ident]
1818 , moduleForeign :: [ForeignDecl]
1919 , moduleDecls :: [Bind a]
20− } deriving (Show, Read)
20+ } deriving (Show)
2121
2222type ForeignDecl = (Ident, Type)
src/Language/PureScript/Docs/AsMarkdown.hs+1−1
@@ -110,7 +110,7 @@ childToString f decl@ChildDeclaration{..} =
110110data First
111111 = First
112112 | NotFirst
113− deriving (Show, Read, Eq, Ord)
113+ deriving (Show, Eq, Ord)
114114
115115type Docs = Writer [String] ()
116116
src/Language/PureScript/Docs/Convert.hs+1−1
@@ -158,7 +158,7 @@ insertValueTypes env m =
158158 either (err . ("failed to parse Ident: " ++)) id . runParser P.parseIdent
159159
160160 lookupName name =
161− let key = (modName m, name)
161+ let key = P.Qualified (Just (modName m)) name
162162 in case Map.lookup key (P.names env) of
163163 Just (ty, _, _) ->
164164 ty
src/Language/PureScript/Environment.hs+7−8
@@ -25,7 +25,7 @@ data Environment = Environment {
2525 -- |
2626 -- Value names currently in scope
2727 --
28− names :: M.Map (ModuleName, Ident) (Type, NameKind, NameVisibility)
28+ names :: M.Map (Qualified Ident) (Type, NameKind, NameVisibility)
2929 -- |
3030 -- Type names currently in scope
3131 --
@@ -46,7 +46,7 @@ data Environment = Environment {
4646 -- Type classes
4747 --
4848 , typeClasses :: M.Map (Qualified (ProperName 'ClassName)) ([(String, Maybe Kind)], [(Ident, Type)], [Constraint])
49− } deriving (Show, Read)
49+ } deriving (Show)
5050
5151-- |
5252-- The initial environment with no values and only the default javascript types defined
@@ -65,7 +65,7 @@ data NameVisibility
6565 -- |
6666 -- The name is defined in the another binding group, or has been made visible by a function binder
6767 --
68− | Defined deriving (Show, Read, Eq)
68+ | Defined deriving (Show, Eq)
6969
7070-- |
7171-- A flag for whether a name is for an private or public value - only public values will be
@@ -85,7 +85,7 @@ data NameKind
8585 -- A name for member introduced by foreign import
8686 --
8787 | External
88− deriving (Show, Read, Eq)
88+ deriving (Show, Eq)
8989
9090-- |
9191-- The kinds of a type
@@ -111,7 +111,7 @@ data TypeKind
111111 -- A scoped type variable
112112 --
113113 | ScopedTypeVar
114− deriving (Show, Read, Eq)
114+ deriving (Show, Eq)
115115
116116-- |
117117-- The type ('data' or 'newtype') of a data type declaration
@@ -125,7 +125,7 @@ data DataDeclType
125125 -- A newtype constructor
126126 --
127127 | Newtype
128− deriving (Show, Read, Eq, Ord)
128+ deriving (Show, Eq, Ord)
129129
130130showDataDeclType :: DataDeclType -> String
131131showDataDeclType Data = "data"
@@ -273,7 +273,6 @@ isNewtypeConstructor e ctor = case lookupConstructor e ctor of
273273-- Finds information about values from the current environment.
274274--
275275lookupValue :: Environment -> Qualified Ident -> Maybe (Type, NameKind, NameVisibility)
276−lookupValue env (Qualified (Just mn) ident) = (mn, ident) `M.lookup` names env
277−lookupValue _ _ = Nothing
276+lookupValue env ident = ident `M.lookup` names env
278277
279278$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''TypeKind)
src/Language/PureScript/Errors.hs+58−164
@@ -1,7 +1,10 @@
11{-# LANGUAGE GeneralizedNewtypeDeriving #-}
22{-# LANGUAGE NamedFieldPuns #-}
33
4−module Language.PureScript.Errors where
4+module Language.PureScript.Errors
5+ ( module Language.PureScript.AST
6+ , module Language.PureScript.Errors
7+ ) where
58
69import Prelude.Compat
710
@@ -14,6 +17,7 @@ import Control.Monad.Writer
1417import Data.Char (isSpace)
1518import Data.Either (lefts, rights)
1619import Data.Foldable (fold)
20+import Data.Functor.Identity (Identity(..))
1721import Data.List (intercalate, transpose, nub, nubBy, sortBy, partition)
1822import Data.Maybe (maybeToList, fromMaybe, mapMaybe)
1923import Data.Ord (comparing)
@@ -21,7 +25,6 @@ import qualified Data.Map as M
2125
2226import Language.PureScript.AST
2327import Language.PureScript.Crash
24−import Language.PureScript.Kinds
2528import Language.PureScript.Names
2629import Language.PureScript.Pretty
2730import Language.PureScript.Traversals
@@ -37,137 +40,6 @@ import qualified Text.Parsec.Error as PE
3740import qualified Text.PrettyPrint.Boxes as Box
3841import Text.Parsec.Error (Message(..))
3942
40−-- | A type of error messages
41−data SimpleErrorMessage
42− = ErrorParsingFFIModule FilePath (Maybe Bundle.ErrorMessage)
43− | ErrorParsingModule P.ParseError
44− | MissingFFIModule ModuleName
45− | MultipleFFIModules ModuleName [FilePath]
46− | UnnecessaryFFIModule ModuleName FilePath
47− | MissingFFIImplementations ModuleName [Ident]
48− | UnusedFFIImplementations ModuleName [Ident]
49− | InvalidFFIIdentifier ModuleName String
50− | CannotGetFileInfo FilePath
51− | CannotReadFile FilePath
52− | CannotWriteFile FilePath
53− | InfiniteType Type
54− | InfiniteKind Kind
55− | MultipleValueOpFixities (OpName 'ValueOpName)
56− | MultipleTypeOpFixities (OpName 'TypeOpName)
57− | OrphanTypeDeclaration Ident
58− | RedefinedModule ModuleName [SourceSpan]
59− | RedefinedIdent Ident
60− | OverlappingNamesInLet
61− | UnknownName (Qualified Name)
62− | UnknownImport ModuleName Name
63− | UnknownImportDataConstructor ModuleName (ProperName 'TypeName) (ProperName 'ConstructorName)
64− | UnknownExport Name
65− | UnknownExportDataConstructor (ProperName 'TypeName) (ProperName 'ConstructorName)
66− | ScopeConflict Name [ModuleName]
67− | ScopeShadowing Name (Maybe ModuleName) [ModuleName]
68− | DeclConflict Name Name
69− | ExportConflict (Qualified Name) (Qualified Name)
70− | DuplicateModuleName ModuleName
71− | DuplicateTypeArgument String
72− | InvalidDoBind
73− | InvalidDoLet
74− | CycleInDeclaration Ident
75− | CycleInTypeSynonym (Maybe (ProperName 'TypeName))
76− | CycleInModules [ModuleName]
77− | NameIsUndefined Ident
78− | UndefinedTypeVariable (ProperName 'TypeName)
79− | PartiallyAppliedSynonym (Qualified (ProperName 'TypeName))
80− | EscapedSkolem (Maybe Expr)
81− | TypesDoNotUnify Type Type
82− | KindsDoNotUnify Kind Kind
83− | ConstrainedTypeUnified Type Type
84− | OverlappingInstances (Qualified (ProperName 'ClassName)) [Type] [Qualified Ident]
85− | NoInstanceFound Constraint
86− | PossiblyInfiniteInstance (Qualified (ProperName 'ClassName)) [Type]
87− | CannotDerive (Qualified (ProperName 'ClassName)) [Type]
88− | CannotFindDerivingType (ProperName 'TypeName)
89− | DuplicateLabel String (Maybe Expr)
90− | DuplicateValueDeclaration Ident
91− | ArgListLengthsDiffer Ident
92− | OverlappingArgNames (Maybe Ident)
93− | MissingClassMember Ident
94− | ExtraneousClassMember Ident (Qualified (ProperName 'ClassName))
95− | ExpectedType Type Kind
96− | IncorrectConstructorArity (Qualified (ProperName 'ConstructorName))
97− | ExprDoesNotHaveType Expr Type
98− | PropertyIsMissing String
99− | AdditionalProperty String
100− | CannotApplyFunction Type Expr
101− | TypeSynonymInstance
102− | OrphanInstance Ident (Qualified (ProperName 'ClassName)) [Type]
103− | InvalidNewtype (ProperName 'TypeName)
104− | InvalidInstanceHead Type
105− | TransitiveExportError DeclarationRef [DeclarationRef]
106− | TransitiveDctorExportError DeclarationRef (ProperName 'ConstructorName)
107− | ShadowedName Ident
108− | ShadowedTypeVar String
109− | UnusedTypeVar String
110− | WildcardInferredType Type
111− | HoleInferredType String Type [(Ident, Type)]
112− | MissingTypeDeclaration Ident Type
113− | OverlappingPattern [[Binder]] Bool
114− | IncompleteExhaustivityCheck
115− | MisleadingEmptyTypeImport ModuleName (ProperName 'TypeName)
116− | ImportHidingModule ModuleName
117− | UnusedImport ModuleName
118− | UnusedExplicitImport ModuleName [String] (Maybe ModuleName) [DeclarationRef]
119− | UnusedDctorImport (ProperName 'TypeName)
120− | UnusedDctorExplicitImport (ProperName 'TypeName) [ProperName 'ConstructorName]
121− | DuplicateSelectiveImport ModuleName
122− | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
123− | DuplicateImportRef Name
124− | DuplicateExportRef Name
125− | IntOutOfRange Integer String Integer Integer
126− | ImplicitQualifiedImport ModuleName ModuleName [DeclarationRef]
127− | ImplicitImport ModuleName [DeclarationRef]
128− | HidingImport ModuleName [DeclarationRef]
129− | CaseBinderLengthDiffers Int [Binder]
130− | IncorrectAnonymousArgument
131− | InvalidOperatorInBinder (Qualified (OpName 'ValueOpName)) (Qualified Ident)
132− | DeprecatedRequirePath
133− | CannotGeneralizeRecursiveFunction Ident Type
134− deriving (Show)
135−
136−-- | Error message hints, providing more detailed information about failure.
137−data ErrorMessageHint
138− = ErrorUnifyingTypes Type Type
139− | ErrorInExpression Expr
140− | ErrorInModule ModuleName
141− | ErrorInInstance (Qualified (ProperName 'ClassName)) [Type]
142− | ErrorInSubsumption Type Type
143− | ErrorCheckingAccessor Expr String
144− | ErrorCheckingType Expr Type
145− | ErrorCheckingKind Type
146− | ErrorCheckingGuard
147− | ErrorInferringType Expr
148− | ErrorInApplication Expr Type Expr
149− | ErrorInDataConstructor (ProperName 'ConstructorName)
150− | ErrorInTypeConstructor (ProperName 'TypeName)
151− | ErrorInBindingGroup [Ident]
152− | ErrorInDataBindingGroup
153− | ErrorInTypeSynonym (ProperName 'TypeName)
154− | ErrorInValueDeclaration Ident
155− | ErrorInTypeDeclaration Ident
156− | ErrorInForeignImport Ident
157− | PositionedError SourceSpan
158− deriving Show
159−
160−-- | Categories of hints
161−data HintCategory
162− = ExprHint
163− | KindHint
164− | CheckHint
165− | PositionHint
166− | OtherHint
167− deriving (Show, Eq)
168−
169−data ErrorMessage = ErrorMessage [ErrorMessageHint] SimpleErrorMessage deriving (Show)
170−
17143newtype ErrorSuggestion = ErrorSuggestion String
17244
17345-- | Get the source span for an error
@@ -321,7 +193,11 @@ onErrorMessages f = MultipleErrors . map f . runMultipleErrors
321193
322194-- | Add a hint to an error message
323195addHint :: ErrorMessageHint -> MultipleErrors -> MultipleErrors
324−addHint hint = onErrorMessages $ \(ErrorMessage hints se) -> ErrorMessage (hint : hints) se
196+addHint hint = addHints [hint]
197+
198+-- | Add hints to an error message
199+addHints :: [ErrorMessageHint] -> MultipleErrors -> MultipleErrors
200+addHints hints = onErrorMessages $ \(ErrorMessage hints' se) -> ErrorMessage (hints ++ hints') se
325201
326202-- | A map from rigid type variable name/unknown variable pairs to new variables.
327203data TypeMap = TypeMap
@@ -368,7 +244,10 @@ replaceUnknowns = everywhereOnTypesM replaceTypes
368244 Just (_, s', _) -> return (Skolem name s' sko ss)
369245 replaceTypes other = return other
370246
371−onTypesInErrorMessageM :: (Applicative m) => (Type -> m Type) -> ErrorMessage -> m ErrorMessage
247+onTypesInErrorMessage :: (Type -> Type) -> ErrorMessage -> ErrorMessage
248+onTypesInErrorMessage f = runIdentity . onTypesInErrorMessageM (Identity . f)
249+
250+onTypesInErrorMessageM :: Applicative m => (Type -> m Type) -> ErrorMessage -> m ErrorMessage
372251onTypesInErrorMessageM f (ErrorMessage hints simple) = ErrorMessage <$> traverse gHint hints <*> gSimple simple
373252 where
374253 gSimple (InfiniteType t) = InfiniteType <$> f t
@@ -383,11 +262,10 @@ onTypesInErrorMessageM f (ErrorMessage hints simple) = ErrorMessage <$> traverse
383262 gSimple (CannotDerive cl ts) = CannotDerive cl <$> traverse f ts
384263 gSimple (ExpectedType ty k) = ExpectedType <$> f ty <*> pure k
385264 gSimple (OrphanInstance nm cl ts) = OrphanInstance nm cl <$> traverse f ts
386− gSimple (WildcardInferredType ty) = WildcardInferredType <$> f ty
387− gSimple (HoleInferredType name ty env) = HoleInferredType name <$> f ty <*> traverse (sndM f) env
265+ gSimple (WildcardInferredType ty ctx) = WildcardInferredType <$> f ty <*> traverse (sndM f) ctx
266+ gSimple (HoleInferredType name ty ctx) = HoleInferredType name <$> f ty <*> traverse (sndM f) ctx
388267 gSimple (MissingTypeDeclaration nm ty) = MissingTypeDeclaration nm <$> f ty
389268 gSimple (CannotGeneralizeRecursiveFunction nm ty) = CannotGeneralizeRecursiveFunction nm <$> f ty
390−
391269 gSimple other = pure other
392270
393271 gHint (ErrorInSubsumption t1 t2) = ErrorInSubsumption <$> f t1 <*> f t2
@@ -396,6 +274,7 @@ onTypesInErrorMessageM f (ErrorMessage hints simple) = ErrorMessage <$> traverse
396274 gHint (ErrorCheckingKind t) = ErrorCheckingKind <$> f t
397275 gHint (ErrorInApplication e1 t1 e2) = ErrorInApplication e1 <$> f t1 <*> pure e2
398276 gHint (ErrorInInstance cl ts) = ErrorInInstance cl <$> traverse f ts
277+ gHint (ErrorSolvingConstraint con) = ErrorSolvingConstraint <$> overConstraintArgs (traverse f) con
399278 gHint other = pure other
400279
401280wikiUri :: ErrorMessage -> String
@@ -413,7 +292,7 @@ errorSuggestion err = case err of
413292 ImplicitQualifiedImport mn asModule refs -> suggest $ importSuggestion mn refs (Just asModule)
414293 HidingImport mn refs -> suggest $ importSuggestion mn refs Nothing
415294 MissingTypeDeclaration ident ty -> suggest $ showIdent ident ++ " :: " ++ prettyPrintType ty
416− WildcardInferredType ty -> suggest $ prettyPrintType ty
295+ WildcardInferredType ty _ -> suggest $ prettyPrintType ty
417296 _ -> Nothing
418297
419298 where
@@ -845,24 +724,14 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
845724 paras [ line "hiding imports cannot be used to hide modules."
846725 , line $ "An attempt was made to hide the import of " ++ markCode (runModuleName name)
847726 ]
848− renderSimpleErrorMessage (WildcardInferredType ty) =
849− paras [ line "Wildcard type definition has the inferred type "
850− , markCodeBox $ indent $ typeAsBox ty
851− ]
852− renderSimpleErrorMessage (HoleInferredType name ty env) =
727+ renderSimpleErrorMessage (WildcardInferredType ty ctx) =
728+ paras $ [ line "Wildcard type definition has the inferred type "
729+ , markCodeBox $ indent $ typeAsBox ty
730+ ] ++ renderContext ctx
731+ renderSimpleErrorMessage (HoleInferredType name ty ctx) =
853732 paras $ [ line $ "Hole '" ++ markCode name ++ "' has the inferred type "
854733 , markCodeBox $ indent $ typeAsBox ty
855− ] ++ if null env then [] else envInfo
856− where
857− envInfo :: [Box.Box]
858− envInfo = [ line "in the following context:"
859− , indent $ paras
860− [ Box.hcat Box.left [ Box.text (showIdent ident <> " :: ")
861− , markCodeBox $ typeAsBox ty'
862− ]
863− | (ident, ty') <- take 5 env
864− ]
865− ]
734+ ] ++ renderContext ctx
866735 renderSimpleErrorMessage (MissingTypeDeclaration ident ty) =
867736 paras [ line $ "No type declaration was provided for the top-level declaration of " ++ markCode (showIdent ident) ++ "."
868737 , line "It is good practice to provide type declarations as a form of documentation."
@@ -1062,11 +931,31 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
1062931 paras [ detail
1063932 , line $ "in foreign import " ++ markCode (showIdent nm)
1064933 ]
934+ renderHint (ErrorSolvingConstraint (Constraint nm ts _)) detail =
935+ paras [ detail
936+ , line "while solving type class constriant"
937+ , markCodeBox $ indent $ Box.hsep 1 Box.left
938+ [ line (showQualified runProperName nm)
939+ , Box.vcat Box.left (map typeAtomAsBox ts)
940+ ]
941+ ]
1065942 renderHint (PositionedError srcSpan) detail =
1066943 paras [ line $ "at " ++ displaySourceSpan srcSpan
1067944 , detail
1068945 ]
1069946
947+ renderContext :: Context -> [Box.Box]
948+ renderContext [] = []
949+ renderContext ctx =
950+ [ line "in the following context:"
951+ , indent $ paras
952+ [ Box.hcat Box.left [ Box.text (showIdent ident <> " :: ")
953+ , markCodeBox $ typeAsBox ty'
954+ ]
955+ | (ident, ty') <- take 5 ctx
956+ ]
957+ ]
958+
1070959 printName :: Qualified Name -> String
1071960 printName qn = nameType (disqualify qn) ++ " " ++ markCode (runName qn)
1072961
@@ -1139,6 +1028,10 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
11391028 where
11401029 isUnifyHint ErrorUnifyingTypes{} = True
11411030 isUnifyHint _ = False
1031+ stripRedudantHints NoInstanceFound{} = stripFirst isSolverHint
1032+ where
1033+ isSolverHint ErrorSolvingConstraint{} = True
1034+ isSolverHint _ = False
11421035 stripRedudantHints _ = id
11431036
11441037 stripFirst :: (ErrorMessageHint -> Bool) -> [ErrorMessageHint] -> [ErrorMessageHint]
@@ -1150,15 +1043,16 @@ prettyPrintSingleError (PPEOptions codeColor full level showWiki) e = flip evalS
11501043 stripFirst _ [] = []
11511044
11521045 hintCategory :: ErrorMessageHint -> HintCategory
1153− hintCategory ErrorCheckingType{} = ExprHint
1154− hintCategory ErrorInferringType{} = ExprHint
1155− hintCategory ErrorInExpression{} = ExprHint
1156− hintCategory ErrorUnifyingTypes{} = CheckHint
1157− hintCategory ErrorInSubsumption{} = CheckHint
1158− hintCategory ErrorInApplication{} = CheckHint
1159− hintCategory ErrorCheckingKind{} = CheckHint
1160− hintCategory PositionedError{} = PositionHint
1161− hintCategory _ = OtherHint
1046+ hintCategory ErrorCheckingType{} = ExprHint
1047+ hintCategory ErrorInferringType{} = ExprHint
1048+ hintCategory ErrorInExpression{} = ExprHint
1049+ hintCategory ErrorUnifyingTypes{} = CheckHint
1050+ hintCategory ErrorInSubsumption{} = CheckHint
1051+ hintCategory ErrorInApplication{} = CheckHint
1052+ hintCategory ErrorCheckingKind{} = CheckHint
1053+ hintCategory ErrorSolvingConstraint{} = SolverHint
1054+ hintCategory PositionedError{} = PositionHint
1055+ hintCategory _ = OtherHint
11621056
11631057-- Pretty print and export declaration
11641058prettyPrintExport :: DeclarationRef -> String
src/Language/PureScript/Externs.hs+7−7
@@ -50,7 +50,7 @@ data ExternsFile = ExternsFile
5050 , efTypeFixities :: [ExternsTypeFixity]
5151 -- | List of type and value declaration
5252 , efDeclarations :: [ExternsDeclaration]
53− } deriving (Show, Read)
53+ } deriving (Show)
5454
5555-- | A module import in an externs file
5656data ExternsImport = ExternsImport
@@ -61,7 +61,7 @@ data ExternsImport = ExternsImport
6161 , eiImportType :: ImportDeclarationType
6262 -- | The imported-as name, for qualified imports
6363 , eiImportedAs :: Maybe ModuleName
64− } deriving (Show, Read)
64+ } deriving (Show)
6565
6666-- | A fixity declaration in an externs file
6767data ExternsFixity = ExternsFixity
@@ -74,7 +74,7 @@ data ExternsFixity = ExternsFixity
7474 , efOperator :: OpName 'ValueOpName
7575 -- | The value the operator is an alias for
7676 , efAlias :: Qualified (Either Ident (ProperName 'ConstructorName))
77− } deriving (Show, Read)
77+ } deriving (Show)
7878
7979-- | A type fixity declaration in an externs file
8080data ExternsTypeFixity = ExternsTypeFixity
@@ -87,7 +87,7 @@ data ExternsTypeFixity = ExternsTypeFixity
8787 , efTypeOperator :: OpName 'TypeOpName
8888 -- | The value the operator is an alias for
8989 , efTypeAlias :: Qualified (ProperName 'TypeName)
90− } deriving (Show, Read)
90+ } deriving (Show)
9191
9292-- | A type or value declaration appearing in an externs file
9393data ExternsDeclaration =
@@ -130,7 +130,7 @@ data ExternsDeclaration =
130130 , edInstanceTypes :: [Type]
131131 , edInstanceConstraints :: Maybe [Constraint]
132132 }
133− deriving (Show, Read)
133+ deriving (Show)
134134
135135-- | Convert an externs file back into a module
136136applyExternsFileToEnvironment :: ExternsFile -> Environment -> Environment
@@ -140,7 +140,7 @@ applyExternsFileToEnvironment ExternsFile{..} = flip (foldl' applyDecl) efDeclar
140140 applyDecl env (EDType pn kind tyKind) = env { types = M.insert (qual pn) (kind, tyKind) (types env) }
141141 applyDecl env (EDTypeSynonym pn args ty) = env { typeSynonyms = M.insert (qual pn) (args, ty) (typeSynonyms env) }
142142 applyDecl env (EDDataConstructor pn dTy tNm ty nms) = env { dataConstructors = M.insert (qual pn) (dTy, tNm, ty, nms) (dataConstructors env) }
143− applyDecl env (EDValue ident ty) = env { names = M.insert (efModuleName, ident) (ty, External, Defined) (names env) }
143+ applyDecl env (EDValue ident ty) = env { names = M.insert (Qualified (Just efModuleName) ident) (ty, External, Defined) (names env) }
144144 applyDecl env (EDClass pn args members cs) = env { typeClasses = M.insert (qual pn) (args, members, cs) (typeClasses env) }
145145 applyDecl env (EDInstance className ident tys cs) = env { typeClassDictionaries = updateMap (updateMap (M.insert (qual ident) dict) className) (Just efModuleName) (typeClassDictionaries env) }
146146 where
@@ -201,7 +201,7 @@ moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
201201 ]
202202 _ -> internalError "toExternsDeclaration: Invalid input"
203203 toExternsDeclaration (ValueRef ident)
204− | Just (ty, _, _) <- (mn, ident) `M.lookup` names env
204+ | Just (ty, _, _) <- Qualified (Just mn) ident `M.lookup` names env
205205 = [ EDValue ident ty ]
206206 toExternsDeclaration (TypeClassRef className)
207207 | Just (args, members, implies) <- Qualified (Just mn) className `M.lookup` typeClasses env
src/Language/PureScript/Ide/Command.hs−1
@@ -24,7 +24,6 @@ import Language.PureScript.Ide.CaseSplit
2424import Language.PureScript.Ide.Filter
2525import Language.PureScript.Ide.Matcher
2626import Language.PureScript.Ide.Types
27−import System.FilePath
2827
2928data Command
3029 = Load [P.ModuleName]
src/Language/PureScript/Ide/Externs.hs−1
@@ -33,7 +33,6 @@ import Language.PureScript.Ide.Types
3333import Language.PureScript.Ide.Util
3434
3535import qualified Language.PureScript as P
36−import System.FilePath
3736
3837readExternFile :: (MonadIO m, MonadError PscIdeError m) =>
3938 FilePath -> m P.ExternsFile
src/Language/PureScript/Ide/Imports.hs−1
@@ -40,7 +40,6 @@ import Language.PureScript.Ide.Filter
4040import Language.PureScript.Ide.State
4141import Language.PureScript.Ide.Types
4242import Language.PureScript.Ide.Util
43−import System.FilePath
4443
4544data Import = Import P.ModuleName P.ImportDeclarationType (Maybe P.ModuleName)
4645 deriving (Eq, Show)
src/Language/PureScript/Ide/Pursuit.hs+2−2
@@ -19,7 +19,7 @@ module Language.PureScript.Ide.Pursuit
1919 , findPackagesForModuleIdent
2020 ) where
2121
22−import Protolude
22+import Protolude hiding (fromStrict)
2323
2424import qualified Control.Exception as E
2525import Data.Aeson
@@ -36,7 +36,7 @@ import qualified Pipes.Prelude as P
3636queryPursuit :: Text -> IO ByteString
3737queryPursuit q = do
3838 let qClean = T.dropWhileEnd (== '.') q
39− req' <- parseUrl "http://pursuit.purescript.org/search"
39+ req' <- parseRequest "http://pursuit.purescript.org/search"
4040 let req = req'
4141 { queryString= "q=" <> (fromString . T.unpack) qClean
4242 , requestHeaders=[(hAccept, "application/json")]
src/Language/PureScript/Ide/Rebuild.hs+2−2
@@ -22,7 +22,6 @@ import Language.PureScript.Ide.State
2222import Language.PureScript.Ide.Types
2323import Language.PureScript.Ide.Util
2424import System.IO.UTF8 (readUTF8File)
25−import System.FilePath
2625
2726-- | Given a filepath performs the following steps:
2827--
@@ -145,7 +144,8 @@ sortExterns m ex = do
145144 . M.elems
146145 . M.delete (P.getModuleName m) $ ex
147146 case sorted' of
148− Left _ -> throwError (GeneralError "There was a cycle in the dependencies")
147+ Left err ->
148+ throwError (RebuildError (toJSONErrors False P.Error err))
149149 Right (sorted, graph) -> do
150150 let deps = fromJust (List.lookup (P.getModuleName m) graph)
151151 pure $ mapMaybe getExtern (deps `inOrderOf` map P.getModuleName sorted)
src/Language/PureScript/Ide/SourceFile.hs−1
@@ -26,7 +26,6 @@ import qualified Language.PureScript as P
2626import Language.PureScript.Ide.Error
2727import Language.PureScript.Ide.Util
2828import Language.PureScript.Ide.Types
29−import System.FilePath
3029import System.IO.UTF8 (readUTF8File)
3130
3231parseModule
src/Language/PureScript/Ide/State.hs−1
@@ -44,7 +44,6 @@ import Language.PureScript.Ide.Types
4444import Language.PureScript.Ide.Util
4545import qualified Language.PureScript as P
4646import System.Clock
47−import System.FilePath
4847
4948-- | Resets all State inside psc-ide
5049resetIdeState :: Ide m => m ()
src/Language/PureScript/Ide/Types.hs−1
@@ -25,7 +25,6 @@ import Data.Map.Lazy as M
2525import qualified Language.PureScript.Errors.JSON as P
2626import qualified Language.PureScript as P
2727import Language.PureScript.Ide.Conversions
28−import System.FilePath
2928import Text.Parsec as Parsec
3029import Text.Parsec.Text
3130
src/Language/PureScript/Ide/Util.hs+1−1
@@ -27,7 +27,7 @@ module Language.PureScript.Ide.Util
2727 , module Language.PureScript.Ide.Conversions
2828 ) where
2929
30−import Protolude
30+import Protolude hiding (decodeUtf8, encodeUtf8)
3131import Data.Aeson
3232import qualified Data.Text as T
3333import Data.Text.Lazy.Encoding (decodeUtf8, encodeUtf8)
src/Language/PureScript/Interactive.hs+1−1
@@ -234,7 +234,7 @@ handleTypeOf val = do
234234 case e of
235235 Left errs -> printErrors errs
236236 Right (_, env') ->
237− case M.lookup (P.ModuleName [P.ProperName "$PSCI"], P.Ident "it") (P.names env') of
237+ case M.lookup (P.mkQualified (P.Ident "it") (P.ModuleName [P.ProperName "$PSCI"])) (P.names env') of
238238 Just (ty, _, _) -> liftIO . putStrLn . P.prettyPrintType $ ty
239239 Nothing -> liftIO $ putStrLn "Could not find type"
240240
src/Language/PureScript/Interactive/Completion.hs+1−1
@@ -91,7 +91,7 @@ data CompletionContext
9191 | CtxIdentifier
9292 | CtxType
9393 | CtxFixed String
94− deriving (Show, Read)
94+ deriving (Show)
9595
9696-- |
9797-- Decide what kind of completion we need based on input. This function expects
src/Language/PureScript/Interactive/Printer.hs+8−5
@@ -19,9 +19,10 @@ import qualified Text.PrettyPrint.Boxes as Box
1919printModuleSignatures :: P.ModuleName -> P.Environment -> String
2020printModuleSignatures moduleName (P.Environment {..}) =
2121 -- get relevant components of a module from environment
22− let moduleNamesIdent = (filter ((== moduleName) . fst) . M.keys) names
23− moduleTypeClasses = (filter (\(P.Qualified maybeName _) -> maybeName == Just moduleName) . M.keys) typeClasses
24− moduleTypes = (filter (\(P.Qualified maybeName _) -> maybeName == Just moduleName) . M.keys) types
22+ let moduleNamesIdent = byModuleName names
23+ moduleTypeClasses = byModuleName typeClasses
24+ moduleTypes = byModuleName types
25+ byModuleName = filter ((== Just moduleName) . P.getQual) . M.keys
2526
2627 in
2728 -- print each component
@@ -33,8 +34,10 @@ printModuleSignatures moduleName (P.Environment {..}) =
3334
3435 where printModule's showF = Box.vsep 1 Box.left . showF
3536
36− findNameType :: M.Map (P.ModuleName, P.Ident) (P.Type, P.NameKind, P.NameVisibility) -> (P.ModuleName, P.Ident) -> (P.Ident, Maybe (P.Type, P.NameKind, P.NameVisibility))
37− findNameType envNames m@(_, mIdent) = (mIdent, M.lookup m envNames)
37+ findNameType :: M.Map (P.Qualified P.Ident) (P.Type, P.NameKind, P.NameVisibility)
38+ -> P.Qualified P.Ident
39+ -> (P.Ident, Maybe (P.Type, P.NameKind, P.NameVisibility))
40+ findNameType envNames m = (P.disqualify m, M.lookup m envNames)
3841
3942 showNameType :: (P.Ident, Maybe (P.Type, P.NameKind, P.NameVisibility)) -> Box.Box
4043 showNameType (mIdent, Just (mType, _, _)) = Box.text (P.showIdent mIdent ++ " :: ") Box.<> P.typeAsBox mType
src/Language/PureScript/Kinds.hs+1−1
@@ -20,7 +20,7 @@ data Kind
2020 | FunKind Kind Kind
2121 -- | Type-level strings
2222 | Symbol
23− deriving (Show, Read, Eq, Ord)
23+ deriving (Show, Eq, Ord)
2424
2525$(A.deriveJSON A.defaultOptions ''Kind)
2626
src/Language/PureScript/Make.hs+4−3
@@ -36,6 +36,7 @@ import Control.Monad.Trans.Except
3636import Control.Monad.Writer.Class (MonadWriter(..))
3737
3838import Data.Aeson (encode, decode)
39+import Data.ByteString.Builder (toLazyByteString, stringUtf8)
3940import Data.Either (partitionEithers)
4041import Data.Foldable (for_)
4142import Data.List (foldl', sort)
@@ -85,7 +86,7 @@ import qualified Text.Parsec as Parsec
8586-- | Progress messages from the make process
8687data ProgressMessage
8788 = CompilingModule ModuleName
88− deriving (Show, Read, Eq, Ord)
89+ deriving (Show, Eq, Ord)
8990
9091-- | Render a progress message
9192renderProgressMessage :: ProgressMessage -> String
@@ -129,7 +130,7 @@ data RebuildPolicy
129130 -- | Never rebuild this module
130131 = RebuildNever
131132 -- | Always rebuild this module
132− | RebuildAlways deriving (Show, Read, Eq, Ord)
133+ | RebuildAlways deriving (Show, Eq, Ord)
133134
134135-- | Rebuild a single module
135136rebuildModule :: forall m. (Monad m, MonadBaseControl IO m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
@@ -252,7 +253,7 @@ make ma@MakeActions{..} ms = do
252253
253254 decodeExterns :: Externs -> Maybe ExternsFile
254255 decodeExterns bs = do
255− externs <- decode (fromString bs)
256+ externs <- decode (toLazyByteString (stringUtf8 bs))
256257 guard $ efVersion externs == showVersion Paths.version
257258 return externs
258259
src/Language/PureScript/Names.hs+5−5
@@ -64,7 +64,7 @@ data Ident
6464 -- A generated name for an identifier
6565 --
6666 | GenIdent (Maybe String) Integer
67− deriving (Show, Read, Eq, Ord)
67+ deriving (Show, Eq, Ord)
6868
6969runIdent :: Ident -> String
7070runIdent (Ident i) = i
@@ -84,7 +84,7 @@ freshIdent' = GenIdent Nothing <$> fresh
8484-- Operator alias names.
8585--
8686newtype OpName (a :: OpNameType) = OpName { runOpName :: String }
87− deriving (Show, Read, Eq, Ord)
87+ deriving (Show, Eq, Ord)
8888
8989instance ToJSON (OpName a) where
9090 toJSON = toJSON . runOpName
@@ -104,7 +104,7 @@ data OpNameType = ValueOpName | TypeOpName
104104-- Proper names, i.e. capitalized names for e.g. module names, type//data constructors.
105105--
106106newtype ProperName (a :: ProperNameType) = ProperName { runProperName :: String }
107− deriving (Show, Read, Eq, Ord)
107+ deriving (Show, Eq, Ord)
108108
109109instance ToJSON (ProperName a) where
110110 toJSON = toJSON . runProperName
@@ -129,7 +129,7 @@ coerceProperName = ProperName . runProperName
129129-- Module names
130130--
131131newtype ModuleName = ModuleName [ProperName 'Namespace]
132− deriving (Show, Read, Eq, Ord)
132+ deriving (Show, Eq, Ord)
133133
134134runModuleName :: ModuleName -> String
135135runModuleName (ModuleName pns) = intercalate "." (runProperName `map` pns)
@@ -146,7 +146,7 @@ moduleNameFromString = ModuleName . splitProperNames
146146-- A qualified name, i.e. a name with an optional module name
147147--
148148data Qualified a = Qualified (Maybe ModuleName) a
149− deriving (Show, Read, Eq, Ord, Functor)
149+ deriving (Show, Eq, Ord, Functor)
150150
151151showQualified :: (a -> String) -> Qualified a -> String
152152showQualified f (Qualified Nothing a) = f a
src/Language/PureScript/Parser/Lexer.hs+1−1
@@ -104,7 +104,7 @@ data Token
104104 | StringLiteral String
105105 | Number (Either Integer Double)
106106 | HoleLit String
107− deriving (Show, Read, Eq, Ord)
107+ deriving (Show, Eq, Ord)
108108
109109prettyPrintToken :: Token -> String
110110prettyPrintToken LParen = "("
src/Language/PureScript/Pretty/Values.hs+1−3
@@ -60,7 +60,7 @@ prettyPrintValue d (Let ds val) =
6060 (text "in " <> prettyPrintValue (d - 1) val)
6161prettyPrintValue d (Do els) =
6262 text "do " <> vcat left (map (prettyPrintDoNotationElement (d - 1)) els)
63−prettyPrintValue _ (TypeClassDictionary (Constraint name tys _) _) = foldl1 beforeWithSpace $ text ("#dict " ++ runProperName (disqualify name)) : map typeAtomAsBox tys
63+prettyPrintValue _ (TypeClassDictionary (Constraint name tys _) _ _) = foldl1 beforeWithSpace $ text ("#dict " ++ runProperName (disqualify name)) : map typeAtomAsBox tys
6464prettyPrintValue _ (SuperClassDictionary name _) = text $ "#dict " ++ runProperName (disqualify name)
6565prettyPrintValue _ (TypeClassDictionaryAccessor className ident) =
6666 text "#dict-accessor " <> text (runProperName (disqualify className)) <> text "." <> text (showIdent ident) <> text ">"
@@ -75,7 +75,6 @@ prettyPrintValue d expr@Op{} = prettyPrintValueAtom d expr
7575prettyPrintValue d expr@BinaryNoParens{} = prettyPrintValueAtom d expr
7676prettyPrintValue d expr@Parens{} = prettyPrintValueAtom d expr
7777prettyPrintValue d expr@UnaryMinus{} = prettyPrintValueAtom d expr
78−prettyPrintValue d expr@ObjectGetter{} = prettyPrintValueAtom d expr
7978
8079-- | Pretty-print an atomic expression, adding parentheses if necessary.
8180prettyPrintValueAtom :: Int -> Expr -> Box
@@ -92,7 +91,6 @@ prettyPrintValueAtom d (TypedValue _ val _) = prettyPrintValueAtom d val
9291prettyPrintValueAtom d (PositionedValue _ _ val) = prettyPrintValueAtom d val
9392prettyPrintValueAtom d (Parens expr) = (text "(" <> prettyPrintValue d expr) `before` text ")"
9493prettyPrintValueAtom d (UnaryMinus expr) = text "(-" <> prettyPrintValue d expr <> text ")"
95−prettyPrintValueAtom _ (ObjectGetter field) = text "_." <> text field
9694prettyPrintValueAtom d expr = (text "(" <> prettyPrintValue d expr) `before` text ")"
9795
9896prettyPrintLiteralValue :: Int -> Literal Expr -> Box
src/Language/PureScript/Publish.hs+2−2
@@ -169,7 +169,7 @@ getModulesAndBookmarks = do
169169 Left err ->
170170 userError (CompileError err)
171171
172−data TreeStatus = Clean | Dirty deriving (Show, Read, Eq, Ord, Enum)
172+data TreeStatus = Clean | Dirty deriving (Show, Eq, Ord, Enum)
173173
174174getGitWorkingTreeStatus :: PrepareM TreeStatus
175175getGitWorkingTreeStatus = do
@@ -273,7 +273,7 @@ data DependencyStatus
273273 | ResolvedVersion String
274274 -- ^ Resolved to a version. The String argument is the resolution tag (eg,
275275 -- "v0.1.0").
276− deriving (Show, Read, Eq)
276+ deriving (Show, Eq)
277277
278278-- Go through all bower dependencies which contain purescript code, and
279279-- extract their versions.
src/Language/PureScript/Sugar/Names/Env.hs+4−4
@@ -49,7 +49,7 @@ data ImportRecord a =
4949 , importSourceModule :: ModuleName
5050 , importProvenance :: ImportProvenance
5151 }
52− deriving (Eq, Ord, Show, Read)
52+ deriving (Eq, Ord, Show)
5353
5454-- |
5555-- Used to track how an import was introduced into scope. This allows us to
@@ -61,7 +61,7 @@ data ImportProvenance
6161 | FromExplicit
6262 | Local
6363 | Prim
64− deriving (Eq, Ord, Show, Read)
64+ deriving (Eq, Ord, Show)
6565
6666type ImportMap a = M.Map (Qualified a) [ImportRecord a]
6767
@@ -104,7 +104,7 @@ data Imports = Imports
104104 -- The "as" names of modules that have been imported qualified.
105105 --
106106 , importedQualModules :: S.Set ModuleName
107− } deriving (Show, Read)
107+ } deriving (Show)
108108
109109nullImports :: Imports
110110nullImports = Imports M.empty M.empty M.empty M.empty M.empty M.empty S.empty S.empty
@@ -155,7 +155,7 @@ data Exports = Exports
155155 -- from.
156156 --
157157 , exportedValueOps :: M.Map (OpName 'ValueOpName) ModuleName
158− } deriving (Show, Read)
158+ } deriving (Show)
159159
160160-- |
161161-- An empty 'Exports' value.
src/Language/PureScript/Sugar/Operators.hs+2−2
@@ -329,9 +329,9 @@ updateTypes goType = (goDecl, goExpr, goBinder)
329329
330330 goExpr :: Maybe SourceSpan -> Expr -> m (Maybe SourceSpan, Expr)
331331 goExpr _ e@(PositionedValue pos _ _) = return (Just pos, e)
332− goExpr pos (TypeClassDictionary (Constraint name tys info) dicts) = do
332+ goExpr pos (TypeClassDictionary (Constraint name tys info) dicts hints) = do
333333 tys' <- traverse (goType' pos) tys
334− return (pos, TypeClassDictionary (Constraint name tys' info) dicts)
334+ return (pos, TypeClassDictionary (Constraint name tys' info) dicts hints)
335335 goExpr pos (SuperClassDictionary cls tys) = do
336336 tys' <- traverse (goType' pos) tys
337337 return (pos, SuperClassDictionary cls tys')
src/Language/PureScript/Sugar/TypeClasses.hs+1−2
@@ -11,9 +11,8 @@ module Language.PureScript.Sugar.TypeClasses
1111import Prelude.Compat
1212
1313import Language.PureScript.Crash
14−import Language.PureScript.AST hiding (isExported)
1514import Language.PureScript.Environment
16−import Language.PureScript.Errors
15+import Language.PureScript.Errors hiding (isExported)
1716import Language.PureScript.Kinds
1817import Language.PureScript.Names
1918import Language.PureScript.Externs
src/Language/PureScript/TypeChecker.hs+5−5
@@ -91,7 +91,7 @@ valueIsNotDefined
9191 -> m ()
9292valueIsNotDefined moduleName name = do
9393 env <- getEnv
94− case M.lookup (moduleName, name) (names env) of
94+ case M.lookup (Qualified (Just moduleName) name) (names env) of
9595 Just _ -> throwError . errorMessage $ RedefinedIdent name
9696 Nothing -> return ()
9797
@@ -104,7 +104,7 @@ addValue
104104 -> m ()
105105addValue moduleName name ty nameKind = do
106106 env <- getEnv
107− putEnv (env { names = M.insert (moduleName, name) (ty, nameKind, Defined) (names env) })
107+ putEnv (env { names = M.insert (Qualified (Just moduleName) name) (ty, nameKind, Defined) (names env) })
108108
109109addTypeClass
110110 :: (MonadState CheckState m)
@@ -259,9 +259,9 @@ typeCheckAll moduleName _ = traverse go
259259 env <- getEnv
260260 kind <- kindOf ty
261261 guardWith (errorMessage (ExpectedType ty kind)) $ kind == Star
262− case M.lookup (moduleName, name) (names env) of
262+ case M.lookup (Qualified (Just moduleName) name) (names env) of
263263 Just _ -> throwError . errorMessage $ RedefinedIdent name
264− Nothing -> putEnv (env { names = M.insert (moduleName, name) (ty, External, Defined) (names env) })
264+ Nothing -> putEnv (env { names = M.insert (Qualified (Just moduleName) name) (ty, External, Defined) (names env) })
265265 return d
266266 go d@FixityDeclaration{} = return d
267267 go d@ImportDeclaration{} = return d
@@ -360,7 +360,7 @@ typeCheckModule (Module ss coms mn decls (Just exps)) =
360360 Just (_, _, ty, _) -> checkExport dr extract ty
361361 return ()
362362 checkMemberExport extract dr@(ValueRef name) = do
363− ty <- lookupVariable mn (Qualified (Just mn) name)
363+ ty <- lookupVariable (Qualified (Just mn) name)
364364 checkExport dr extract ty
365365 checkMemberExport _ _ = return ()
366366
src/Language/PureScript/TypeChecker/Entailment.hs+21−19
@@ -2,7 +2,7 @@
22-- Type class entailment
33--
44module Language.PureScript.TypeChecker.Entailment
5− ( Context
5+ ( InstanceContext
66 , replaceTypeClassDictionaries
77 ) where
88
@@ -22,24 +22,25 @@ import Language.PureScript.AST
2222import Language.PureScript.Crash
2323import Language.PureScript.Errors
2424import Language.PureScript.Names
25+import Language.PureScript.TypeChecker.Monad (CheckState, withErrorMessageHint)
2526import Language.PureScript.TypeChecker.Unify
2627import Language.PureScript.TypeClassDictionaries
2728import Language.PureScript.Types
2829import qualified Language.PureScript.Constants as C
2930
30−-- | The 'Context' tracks those constraints which can be satisfied.
31−type Context = M.Map (Maybe ModuleName)
32− (M.Map (Qualified (ProperName 'ClassName))
33− (M.Map (Qualified Ident)
34− TypeClassDictionaryInScope))
31+-- | The 'InstanceContext' tracks those constraints which can be satisfied.
32+type InstanceContext = M.Map (Maybe ModuleName)
33+ (M.Map (Qualified (ProperName 'ClassName))
34+ (M.Map (Qualified Ident)
35+ TypeClassDictionaryInScope))
3536
3637-- | Merge two type class contexts
37−combineContexts :: Context -> Context -> Context
38+combineContexts :: InstanceContext -> InstanceContext -> InstanceContext
3839combineContexts = M.unionWith (M.unionWith M.union)
3940
4041-- | Replace type class dictionary placeholders with inferred type class dictionaries
4142replaceTypeClassDictionaries
42− :: (MonadError MultipleErrors m, MonadWriter MultipleErrors m, MonadSupply m)
43+ :: (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m, MonadSupply m)
4344 => Bool
4445 -> ModuleName
4546 -> Expr
@@ -48,7 +49,8 @@ replaceTypeClassDictionaries shouldGeneralize mn =
4849 let (_, f, _) = everywhereOnValuesTopDownM return (WriterT . go) return
4950 in flip evalStateT M.empty . runWriterT . f
5051 where
51− go (TypeClassDictionary constraint dicts) = entails shouldGeneralize mn dicts constraint
52+ go (TypeClassDictionary constraint dicts hints) =
53+ rethrow (addHints hints) $ entails shouldGeneralize mn dicts constraint
5254 go other = return (other, [])
5355
5456-- |
@@ -57,15 +59,15 @@ replaceTypeClassDictionaries shouldGeneralize mn =
5759--
5860entails
5961 :: forall m
60− . (MonadError MultipleErrors m, MonadWriter MultipleErrors m, MonadSupply m)
62+ . (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m, MonadSupply m)
6163 => Bool
6264 -> ModuleName
63− -> Context
65+ -> InstanceContext
6466 -> Constraint
65− -> StateT Context m (Expr, [(Ident, Constraint)])
67+ -> StateT InstanceContext m (Expr, [(Ident, Constraint)])
6668entails shouldGeneralize moduleName context = solve
6769 where
68− forClassName :: Context -> Qualified (ProperName 'ClassName) -> [Type] -> [TypeClassDictionaryInScope]
70+ forClassName :: InstanceContext -> Qualified (ProperName 'ClassName) -> [Type] -> [TypeClassDictionaryInScope]
6971 forClassName ctx cn@(Qualified (Just mn) _) tys = concatMap (findDicts ctx cn) (Nothing : Just mn : map Just (mapMaybe ctorModules tys))
7072 forClassName _ _ _ = internalError "forClassName: expected qualified class name"
7173
@@ -75,15 +77,15 @@ entails shouldGeneralize moduleName context = solve
7577 ctorModules (TypeApp ty _) = ctorModules ty
7678 ctorModules _ = Nothing
7779
78− findDicts :: Context -> Qualified (ProperName 'ClassName) -> Maybe ModuleName -> [TypeClassDictionaryInScope]
80+ findDicts :: InstanceContext -> Qualified (ProperName 'ClassName) -> Maybe ModuleName -> [TypeClassDictionaryInScope]
7981 findDicts ctx cn = maybe [] M.elems . (>>= M.lookup cn) . flip M.lookup ctx
8082
81− solve :: Constraint -> StateT Context m (Expr, [(Ident, Constraint)])
82− solve con = do
83+ solve :: Constraint -> StateT InstanceContext m (Expr, [(Ident, Constraint)])
84+ solve con = StateT . (withErrorMessageHint (ErrorSolvingConstraint con) .) . runStateT $ do
8385 (dict, unsolved) <- go 0 con
8486 return (dictionaryValueToValue dict, unsolved)
8587 where
86− go :: Int -> Constraint -> StateT Context m (DictionaryValue, [(Ident, Constraint)])
88+ go :: Int -> Constraint -> StateT InstanceContext m (DictionaryValue, [(Ident, Constraint)])
8789 go work (Constraint className' tys' _) | work > 1000 = throwError . errorMessage $ PossiblyInfiniteInstance className' tys'
8890 go work con'@(Constraint className' tys' _) = do
8991 -- Get the inferred constraint context so far, and merge it with the global context
@@ -106,7 +108,7 @@ entails shouldGeneralize moduleName context = solve
106108 -- Generate a fresh name for the unsolved constraint's new dictionary
107109 ident <- freshIdent ("dict" ++ runProperName pn)
108110 let qident = Qualified Nothing ident
109− -- Store the new dictionary in the Context so that we can solve this goal in
111+ -- Store the new dictionary in the InstanceContext so that we can solve this goal in
110112 -- future.
111113 let newDict = TypeClassDictionaryInScope qident [] unsolvedClassName unsolvedTys Nothing
112114 newContext = M.singleton Nothing (M.singleton unsolvedClassName (M.singleton qident newDict))
@@ -143,7 +145,7 @@ entails shouldGeneralize moduleName context = solve
143145 -- Create dictionaries for subgoals which still need to be solved by calling go recursively
144146 -- E.g. the goal (Show a, Show b) => Show (Either a b) can be satisfied if the current type
145147 -- unifies with Either a b, and we can satisfy the subgoals Show a and Show b recursively.
146− solveSubgoals :: [(String, Type)] -> Maybe [Constraint] -> StateT Context m (Maybe [DictionaryValue], [(Ident, Constraint)])
148+ solveSubgoals :: [(String, Type)] -> Maybe [Constraint] -> StateT InstanceContext m (Maybe [DictionaryValue], [(Ident, Constraint)])
147149 solveSubgoals _ Nothing = return (Nothing, [])
148150 solveSubgoals subst (Just subgoals) = do
149151 zipped <- traverse (go (work + 1) . mapConstraintArgs (map (replaceAllTypeVars subst))) subgoals
src/Language/PureScript/TypeChecker/Kinds.hs+2−2
@@ -107,7 +107,7 @@ kindOfWithScopedVars ::
107107 Type ->
108108 m (Kind, [(String, Kind)])
109109kindOfWithScopedVars ty =
110− rethrow (addHint (ErrorCheckingKind ty)) $
110+ withErrorMessageHint (ErrorCheckingKind ty) $
111111 fmap tidyUp . liftUnify $ infer ty
112112 where
113113 tidyUp ((k, args), sub) = ( starIfUnknown (substituteKind sub k)
@@ -200,7 +200,7 @@ infer
200200 :: (MonadError MultipleErrors m, MonadState CheckState m)
201201 => Type
202202 -> m (Kind, [(String, Kind)])
203−infer ty = rethrow (addHint (ErrorCheckingKind ty)) $ infer' ty
203+infer ty = withErrorMessageHint (ErrorCheckingKind ty) $ infer' ty
204204
205205infer'
206206 :: forall m
src/Language/PureScript/TypeChecker/Monad.hs+68−27
@@ -35,18 +35,30 @@ emptySubstitution = Substitution M.empty M.empty
3535
3636-- | State required for type checking
3737data CheckState = CheckState
38− { checkEnv :: Environment -- ^ The current @Environment@
39− , checkNextType :: Int -- ^ The next type unification variable
40− , checkNextKind :: Int -- ^ The next kind unification variable
41− , checkNextSkolem :: Int -- ^ The next skolem variable
42− , checkNextSkolemScope :: Int -- ^ The next skolem scope constant
43− , checkCurrentModule :: Maybe ModuleName -- ^ The current module
44− , checkSubstitution :: Substitution -- ^ The current substitution
38+ { checkEnv :: Environment
39+ -- ^ The current @Environment@
40+ , checkNextType :: Int
41+ -- ^ The next type unification variable
42+ , checkNextKind :: Int
43+ -- ^ The next kind unification variable
44+ , checkNextSkolem :: Int
45+ -- ^ The next skolem variable
46+ , checkNextSkolemScope :: Int
47+ -- ^ The next skolem scope constant
48+ , checkCurrentModule :: Maybe ModuleName
49+ -- ^ The current module
50+ , checkSubstitution :: Substitution
51+ -- ^ The current substitution
52+ , checkHints :: [ErrorMessageHint]
53+ -- ^ The current error message hint stack.
54+ -- This goes into state, rather than using 'rethrow',
55+ -- since this way, we can provide good error messages
56+ -- during instance resolution.
4557 }
4658
4759-- | Create an empty @CheckState@
4860emptyCheckState :: Environment -> CheckState
49−emptyCheckState env = CheckState env 0 0 0 0 Nothing emptySubstitution
61+emptyCheckState env = CheckState env 0 0 0 0 Nothing emptySubstitution []
5062
5163-- | Unification variables
5264type Unknown = Int
@@ -54,7 +66,7 @@ type Unknown = Int
5466-- | Temporarily bind a collection of names to values
5567bindNames
5668 :: MonadState CheckState m
57− => M.Map (ModuleName, Ident) (Type, NameKind, NameVisibility)
69+ => M.Map (Qualified Ident) (Type, NameKind, NameVisibility)
5870 -> m a
5971 -> m a
6072bindNames newNames action = do
@@ -91,6 +103,33 @@ withScopedTypeVars mn ks ma = do
91103 tell . errorMessage $ ShadowedTypeVar name
92104 bindTypes (M.fromList (map (\(name, k) -> (Qualified (Just mn) (ProperName name), (k, ScopedTypeVar))) ks)) ma
93105
106+withErrorMessageHint
107+ :: (MonadState CheckState m, MonadError MultipleErrors m)
108+ => ErrorMessageHint
109+ -> m a
110+ -> m a
111+withErrorMessageHint hint action = do
112+ orig <- get
113+ modify $ \st -> st { checkHints = hint : checkHints st }
114+ -- Need to use 'rethrow' anyway, since we have to handle regular errors
115+ a <- rethrow (addHint hint) action
116+ modify $ \st -> st { checkHints = checkHints orig }
117+ return a
118+
119+rethrowWithPositionTC
120+ :: (MonadState CheckState m, MonadError MultipleErrors m)
121+ => SourceSpan
122+ -> m a
123+ -> m a
124+rethrowWithPositionTC pos = withErrorMessageHint (PositionedError pos)
125+
126+warnAndRethrowWithPositionTC
127+ :: (MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
128+ => SourceSpan
129+ -> m a
130+ -> m a
131+warnAndRethrowWithPositionTC pos = rethrowWithPositionTC pos . warnWithPosition pos
132+
94133-- | Temporarily make a collection of type class dictionaries available
95134withTypeClassDictionaries
96135 :: MonadState CheckState m
@@ -121,12 +160,11 @@ lookupTypeClassDictionaries mn = fromMaybe M.empty . M.lookup mn . typeClassDict
121160-- | Temporarily bind a collection of names to local variables
122161bindLocalVariables
123162 :: (MonadState CheckState m)
124− => ModuleName
125− -> [(Ident, Type, NameVisibility)]
163+ => [(Ident, Type, NameVisibility)]
126164 -> m a
127165 -> m a
128−bindLocalVariables moduleName bindings =
129− bindNames (M.fromList $ flip map bindings $ \(name, ty, visibility) -> ((moduleName, name), (ty, Private, visibility)))
166+bindLocalVariables bindings =
167+ bindNames (M.fromList $ flip map bindings $ \(name, ty, visibility) -> (Qualified Nothing name, (ty, Private, visibility)))
130168
131169-- | Temporarily bind a collection of names to local type variables
132170bindLocalTypeVariables
@@ -157,35 +195,32 @@ preservingNames action = do
157195-- | Lookup the type of a value by name in the @Environment@
158196lookupVariable
159197 :: (e ~ MultipleErrors, MonadState CheckState m, MonadError e m)
160− => ModuleName
161− -> Qualified Ident
198+ => Qualified Ident
162199 -> m Type
163−lookupVariable currentModule (Qualified moduleName var) = do
200+lookupVariable qual = do
164201 env <- getEnv
165− case M.lookup (fromMaybe currentModule moduleName, var) (names env) of
166− Nothing -> throwError . errorMessage $ NameIsUndefined var
202+ case M.lookup qual (names env) of
203+ Nothing -> throwError . errorMessage $ NameIsUndefined (disqualify qual)
167204 Just (ty, _, _) -> return ty
168205
169206-- | Lookup the visibility of a value by name in the @Environment@
170207getVisibility
171208 :: (e ~ MultipleErrors, MonadState CheckState m, MonadError e m)
172− => ModuleName
173− -> Qualified Ident
209+ => Qualified Ident
174210 -> m NameVisibility
175−getVisibility currentModule (Qualified moduleName var) = do
211+getVisibility qual = do
176212 env <- getEnv
177− case M.lookup (fromMaybe currentModule moduleName, var) (names env) of
178− Nothing -> throwError . errorMessage $ NameIsUndefined var
213+ case M.lookup qual (names env) of
214+ Nothing -> throwError . errorMessage $ NameIsUndefined (disqualify qual)
179215 Just (_, _, vis) -> return vis
180216
181217-- | Assert that a name is visible
182218checkVisibility
183219 :: (e ~ MultipleErrors, MonadState CheckState m, MonadError e m)
184− => ModuleName
185− -> Qualified Ident
220+ => Qualified Ident
186221 -> m ()
187−checkVisibility currentModule name@(Qualified _ var) = do
188− vis <- getVisibility currentModule name
222+checkVisibility name@(Qualified _ var) = do
223+ vis <- getVisibility name
189224 case vis of
190225 Undefined -> throwError . errorMessage $ CycleInDeclaration var
191226 _ -> return ()
@@ -206,6 +241,12 @@ lookupTypeVariable currentModule (Qualified moduleName name) = do
206241getEnv :: (MonadState CheckState m) => m Environment
207242getEnv = checkEnv <$> get
208243
244+-- | Get locally-bound names in context, to create an error message.
245+getLocalContext :: MonadState CheckState m => m Context
246+getLocalContext = do
247+ env <- getEnv
248+ return [ (ident, ty') | ((Qualified Nothing ident@Ident{}), (ty', _, Defined)) <- M.toList (names env) ]
249+
209250-- | Update the @Environment@
210251putEnv :: (MonadState CheckState m) => Environment -> m ()
211252putEnv env = modify (\s -> s { checkEnv = env })
src/Language/PureScript/TypeChecker/Subsumption.hs+4−3
@@ -8,7 +8,7 @@ module Language.PureScript.TypeChecker.Subsumption
88import Prelude.Compat
99
1010import Control.Monad.Error.Class (MonadError(..))
11−import Control.Monad.State.Class (MonadState(..))
11+import Control.Monad.State.Class (MonadState(..), gets)
1212
1313import Data.List (sortBy)
1414import Data.Ord (comparing)
@@ -24,7 +24,7 @@ import Language.PureScript.Types
2424
2525-- | Check that one type subsumes another, rethrowing errors to provide a better error message
2626subsumes :: (MonadError MultipleErrors m, MonadState CheckState m) => Maybe Expr -> Type -> Type -> m (Maybe Expr)
27−subsumes val ty1 ty2 = rethrow (addHint (ErrorInSubsumption ty1 ty2)) $ subsumes' val ty1 ty2
27+subsumes val ty1 ty2 = withErrorMessageHint (ErrorInSubsumption ty1 ty2) $ subsumes' val ty1 ty2
2828
2929-- | Check tahat one type subsumes another
3030subsumes' :: (MonadError MultipleErrors m, MonadState CheckState m) =>
@@ -52,7 +52,8 @@ subsumes' val ty1 (KindedType ty2 _) =
5252 subsumes val ty1 ty2
5353subsumes' (Just val) (ConstrainedType constraints ty1) ty2 = do
5454 dicts <- getTypeClassDictionaries
55− subsumes' (Just $ foldl App val (map (flip TypeClassDictionary dicts) constraints)) ty1 ty2
55+ hints <- gets checkHints
56+ subsumes' (Just $ foldl App val (map (\cs -> TypeClassDictionary cs dicts hints) constraints)) ty1 ty2
5657subsumes' val (TypeApp f1 r1) (TypeApp f2 r2) | f1 == tyRecord && f2 == tyRecord = do
5758 let
5859 (ts1, r1') = rowToList r1
src/Language/PureScript/TypeChecker/Types.hs+60−66
@@ -26,7 +26,6 @@ module Language.PureScript.TypeChecker.Types
2626
2727import Prelude.Compat
2828
29−import Control.Arrow (second)
3029import Control.Monad
3130import Control.Monad.Error.Class (MonadError(..))
3231import Control.Monad.State.Class (MonadState(..), gets)
@@ -71,7 +70,7 @@ typesOf ::
7170 m [(Ident, (Expr, Type))]
7271typesOf bindingGroupType moduleName vals = do
7372 tys <- fmap tidyUp . escalateWarningWhen isHoleError . liftUnifyWarnings replace $ do
74− (untyped, typed, dict, untypedDict) <- typeDictionaryForBindingGroup moduleName vals
73+ (untyped, typed, dict, untypedDict) <- typeDictionaryForBindingGroup (Just moduleName) vals
7574 ds1 <- parU typed $ \e -> checkTypedBindingGroupElement moduleName e dict
7675 ds2 <- forM untyped $ \e -> typeForBindingGroupElement e dict untypedDict
7776 return (map (\x -> (False, x)) ds1 ++ map (\x -> (True, x)) ds2)
@@ -117,26 +116,21 @@ typesOf bindingGroupType moduleName vals = do
117116 tidyUp (ts, sub) = map (\(b, (i, (val, ty))) -> (b, (i, (overTypes (substituteType sub) val, substituteType sub ty)))) ts
118117
119118 -- Replace all the wildcards types with their inferred types
120− replace sub (ErrorMessage hints (WildcardInferredType ty)) =
121− ErrorMessage hints . WildcardInferredType $ substituteType sub ty
122− replace sub (ErrorMessage hints (HoleInferredType name ty env)) =
123− ErrorMessage hints $ HoleInferredType name (substituteType sub ty)
124− (map (second (substituteType sub)) env)
125− replace _ em = em
119+ replace sub = onTypesInErrorMessage (substituteType sub)
126120
127121 isHoleError :: ErrorMessage -> Bool
128122 isHoleError (ErrorMessage _ HoleInferredType{}) = True
129123 isHoleError _ = False
130124
131−type TypeData = M.Map (ModuleName, Ident) (Type, NameKind, NameVisibility)
125+type TypeData = M.Map (Qualified Ident) (Type, NameKind, NameVisibility)
132126
133127type UntypedData = [(Ident, Type)]
134128
135−typeDictionaryForBindingGroup ::
136− (MonadState CheckState m) =>
137− ModuleName ->
138− [(Ident, Expr)] ->
139− m ([(Ident, Expr)], [(Ident, (Expr, Type, Bool))], TypeData, UntypedData)
129+typeDictionaryForBindingGroup
130+ :: (MonadState CheckState m)
131+ => Maybe ModuleName
132+ -> [(Ident, Expr)]
133+ -> m ([(Ident, Expr)], [(Ident, (Expr, Type, Bool))], TypeData, UntypedData)
140134typeDictionaryForBindingGroup moduleName vals = do
141135 let
142136 -- Map each declaration to a name/value pair, with an optional type, if the declaration is typed
@@ -154,15 +148,15 @@ typeDictionaryForBindingGroup moduleName vals = do
154148 -- Make a map of names to the unification variables of untyped declarations
155149 untypedDict = zip (map fst untyped) untypedNames
156150 -- Create the dictionary of all name/type pairs, which will be added to the environment during type checking
157− dict = M.fromList (map (\(ident, ty) -> ((moduleName, ident), (ty, Private, Undefined))) $ typedDict ++ untypedDict)
151+ dict = M.fromList (map (\(ident, ty) -> ((Qualified moduleName ident), (ty, Private, Undefined))) $ typedDict ++ untypedDict)
158152 return (untyped, typed, dict, untypedDict)
159153
160−checkTypedBindingGroupElement ::
161− (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
162− ModuleName ->
163− (Ident, (Expr, Type, Bool)) ->
164− TypeData ->
165− m (Ident, (Expr, Type))
154+checkTypedBindingGroupElement
155+ :: (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
156+ => ModuleName
157+ -> (Ident, (Expr, Type, Bool))
158+ -> TypeData
159+ -> m (Ident, (Expr, Type))
166160checkTypedBindingGroupElement mn (ident, (val', ty, checkType)) dict = do
167161 -- Replace type wildcards
168162 ty' <- replaceTypeWildcards ty
@@ -176,12 +170,12 @@ checkTypedBindingGroupElement mn (ident, (val', ty, checkType)) dict = do
176170 else return (TypedValue False val' ty'')
177171 return (ident, (val'', ty''))
178172
179−typeForBindingGroupElement ::
180− (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
181− (Ident, Expr) ->
182− TypeData ->
183− UntypedData ->
184− m (Ident, (Expr, Type))
173+typeForBindingGroupElement
174+ :: (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
175+ => (Ident, Expr)
176+ -> TypeData
177+ -> UntypedData
178+ -> m (Ident, (Expr, Type))
185179typeForBindingGroupElement (ident, val) dict untypedDict = do
186180 -- Infer the type with the new names in scope
187181 TypedValue _ val' ty <- bindNames dict $ infer val
@@ -201,7 +195,7 @@ overTypes f = let (_, f', _) = everywhereOnValues id g id in f'
201195 where
202196 g :: Expr -> Expr
203197 g (TypedValue checkTy val t) = TypedValue checkTy val (f t)
204− g (TypeClassDictionary c sco) = TypeClassDictionary (mapConstraintArgs (map f) c) sco
198+ g (TypeClassDictionary c sco hints) = TypeClassDictionary (mapConstraintArgs (map f) c) sco hints
205199 g other = other
206200
207201-- | Check the kind of a type, failing if it is not of kind *.
@@ -227,7 +221,8 @@ instantiatePolyTypeWithUnknowns val (ForAll ident ty _) = do
227221 instantiatePolyTypeWithUnknowns val ty'
228222instantiatePolyTypeWithUnknowns val (ConstrainedType constraints ty) = do
229223 dicts <- getTypeClassDictionaries
230− instantiatePolyTypeWithUnknowns (foldl App val (map (flip TypeClassDictionary dicts) constraints)) ty
224+ hints <- gets checkHints
225+ instantiatePolyTypeWithUnknowns (foldl App val (map (\cs -> TypeClassDictionary cs dicts hints) constraints)) ty
231226instantiatePolyTypeWithUnknowns val ty = return (val, ty)
232227
233228-- | Infer a type for a value, rethrowing any error to provide a more useful error message
@@ -235,7 +230,7 @@ infer ::
235230 (MonadSupply m, MonadState CheckState m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) =>
236231 Expr ->
237232 m Expr
238−infer val = rethrow (addHint (ErrorInferringType val)) $ infer' val
233+infer val = withErrorMessageHint (ErrorInferringType val) $ infer' val
239234
240235-- | Infer a type for a value
241236infer' ::
@@ -250,8 +245,11 @@ infer' v@(Literal (BooleanLiteral _)) = return $ TypedValue True v tyBoolean
250245infer' (Literal (ArrayLiteral vals)) = do
251246 ts <- traverse infer vals
252247 els <- freshType
253− forM_ ts $ \(TypedValue _ _ t) -> unifyTypes els t
254− return $ TypedValue True (Literal (ArrayLiteral ts)) (TypeApp tyArray els)
248+ ts' <- forM ts $ \(TypedValue ch val t) -> do
249+ (val', t') <- instantiatePolyTypeWithUnknowns val t
250+ unifyTypes els t'
251+ return (TypedValue ch val' t')
252+ return $ TypedValue True (Literal (ArrayLiteral ts')) (TypeApp tyArray els)
255253infer' (Literal (ObjectLiteral ps)) = do
256254 ensureNoDuplicateProperties ps
257255 ts <- traverse (infer . snd) ps
@@ -267,15 +265,14 @@ infer' (ObjectUpdate o ps) = do
267265 let oldTy = TypeApp tyRecord $ rowFromList (oldTys, row)
268266 o' <- TypedValue True <$> check o oldTy <*> pure oldTy
269267 return $ TypedValue True (ObjectUpdate o' newVals) $ TypeApp tyRecord $ rowFromList (newTys, row)
270−infer' (Accessor prop val) = rethrow (addHint (ErrorCheckingAccessor val prop)) $ do
268+infer' (Accessor prop val) = withErrorMessageHint (ErrorCheckingAccessor val prop) $ do
271269 field <- freshType
272270 rest <- freshType
273271 typed <- check val (TypeApp tyRecord (RCons prop field rest))
274272 return $ TypedValue True (Accessor prop typed) field
275273infer' (Abs (Left arg) ret) = do
276274 ty <- freshType
277− Just moduleName <- checkCurrentModule <$> get
278− withBindingGroupVisible $ bindLocalVariables moduleName [(arg, ty, Defined)] $ do
275+ withBindingGroupVisible $ bindLocalVariables [(arg, ty, Defined)] $ do
279276 body@(TypedValue _ _ bodyTy) <- infer' ret
280277 return $ TypedValue True (Abs (Left arg) body) $ function ty bodyTy
281278infer' (Abs (Right _) _) = internalError "Binder was not desugared"
@@ -284,13 +281,13 @@ infer' (App f arg) = do
284281 (ret, app) <- checkFunctionApplication f' ft arg Nothing
285282 return $ TypedValue True app ret
286283infer' (Var var) = do
287− Just moduleName <- checkCurrentModule <$> get
288− checkVisibility moduleName var
289− ty <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards <=< lookupVariable moduleName $ var
284+ checkVisibility var
285+ ty <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards <=< lookupVariable $ var
290286 case ty of
291287 ConstrainedType constraints ty' -> do
292288 dicts <- getTypeClassDictionaries
293− return $ TypedValue True (foldl App (Var var) (map (flip TypeClassDictionary dicts) constraints)) ty'
289+ hints <- gets checkHints
290+ return $ TypedValue True (foldl App (Var var) (map (\cs -> TypeClassDictionary cs dicts hints) constraints)) ty'
294291 _ -> return $ TypedValue True (Var var) ty
295292infer' v@(Constructor c) = do
296293 env <- getEnv
@@ -316,7 +313,8 @@ infer' (Let ds val) = do
316313 return $ TypedValue True (Let ds' val') valTy
317314infer' (SuperClassDictionary className tys) = do
318315 dicts <- getTypeClassDictionaries
319− return $ TypeClassDictionary (Constraint className tys Nothing) dicts
316+ hints <- gets checkHints
317+ return $ TypeClassDictionary (Constraint className tys Nothing) dicts hints
320318infer' (TypedValue checkType val ty) = do
321319 Just moduleName <- checkCurrentModule <$> get
322320 (kind, args) <- kindOfWithScopedVars ty
@@ -326,12 +324,10 @@ infer' (TypedValue checkType val ty) = do
326324 return $ TypedValue True val' ty'
327325infer' (Hole name) = do
328326 ty <- freshType
329− env <- M.toList . names <$> getEnv
330− Just moduleName <- checkCurrentModule <$> get
331− let ctx = [ (ident, ty') | ((mn, ident@Ident{}), (ty', _, Defined)) <- env, mn == moduleName ]
327+ ctx <- getLocalContext
332328 tell . errorMessage $ HoleInferredType name ty ctx
333329 return $ TypedValue True (Hole name) ty
334−infer' (PositionedValue pos c val) = warnAndRethrowWithPosition pos $ do
330+infer' (PositionedValue pos c val) = warnAndRethrowWithPositionTC pos $ do
335331 TypedValue t v ty <- infer' val
336332 return $ TypedValue t (PositionedValue pos c v) ty
337333infer' v = internalError $ "Invalid argument to infer: " ++ show v
@@ -348,27 +344,26 @@ inferLetBinding seen (ValueDeclaration ident nameKind [] (Right (tv@(TypedValue
348344 Just moduleName <- checkCurrentModule <$> get
349345 (kind, args) <- kindOfWithScopedVars ty
350346 checkTypeKind ty kind
351− let dict = M.singleton (moduleName, ident) (ty, nameKind, Undefined)
347+ let dict = M.singleton (Qualified Nothing ident) (ty, nameKind, Undefined)
352348 ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty
353349 TypedValue _ val' ty'' <- if checkType then withScopedTypeVars moduleName args (bindNames dict (check val ty')) else return tv
354− bindNames (M.singleton (moduleName, ident) (ty'', nameKind, Defined)) $ inferLetBinding (seen ++ [ValueDeclaration ident nameKind [] (Right (TypedValue checkType val' ty''))]) rest ret j
350+ bindNames (M.singleton (Qualified Nothing ident) (ty'', nameKind, Defined)) $ inferLetBinding (seen ++ [ValueDeclaration ident nameKind [] (Right (TypedValue checkType val' ty''))]) rest ret j
355351inferLetBinding seen (ValueDeclaration ident nameKind [] (Right val) : rest) ret j = do
356352 valTy <- freshType
357− Just moduleName <- checkCurrentModule <$> get
358− let dict = M.singleton (moduleName, ident) (valTy, nameKind, Undefined)
353+ let dict = M.singleton (Qualified Nothing ident) (valTy, nameKind, Undefined)
359354 TypedValue _ val' valTy' <- bindNames dict $ infer val
360355 unifyTypes valTy valTy'
361− bindNames (M.singleton (moduleName, ident) (valTy', nameKind, Defined)) $ inferLetBinding (seen ++ [ValueDeclaration ident nameKind [] (Right val')]) rest ret j
356+ bindNames (M.singleton (Qualified Nothing ident) (valTy', nameKind, Defined)) $ inferLetBinding (seen ++ [ValueDeclaration ident nameKind [] (Right val')]) rest ret j
362357inferLetBinding seen (BindingGroupDeclaration ds : rest) ret j = do
363358 Just moduleName <- checkCurrentModule <$> get
364− (untyped, typed, dict, untypedDict) <- typeDictionaryForBindingGroup moduleName (map (\(i, _, v) -> (i, v)) ds)
359+ (untyped, typed, dict, untypedDict) <- typeDictionaryForBindingGroup Nothing (map (\(i, _, v) -> (i, v)) ds)
365360 ds1' <- parU typed $ \e -> checkTypedBindingGroupElement moduleName e dict
366361 ds2' <- forM untyped $ \e -> typeForBindingGroupElement e dict untypedDict
367362 let ds' = [(ident, Private, val') | (ident, (val', _)) <- ds1' ++ ds2']
368363 bindNames dict $ do
369364 makeBindingGroupVisible
370365 inferLetBinding (seen ++ [BindingGroupDeclaration ds']) rest ret j
371−inferLetBinding seen (PositionedDeclaration pos com d : ds) ret j = warnAndRethrowWithPosition pos $ do
366+inferLetBinding seen (PositionedDeclaration pos com d : ds) ret j = warnAndRethrowWithPositionTC pos $ do
372367 (d' : ds', val') <- inferLetBinding seen (d : ds) ret j
373368 return (PositionedDeclaration pos com d' : ds', val')
374369inferLetBinding _ _ _ _ = internalError "Invalid argument to inferLetBinding"
@@ -426,7 +421,7 @@ inferBinder val (NamedBinder name binder) = do
426421 m <- inferBinder val binder
427422 return $ M.insert name val m
428423inferBinder val (PositionedBinder pos _ binder) =
429− warnAndRethrowWithPosition pos $ inferBinder val binder
424+ warnAndRethrowWithPositionTC pos $ inferBinder val binder
430425-- TODO: When adding support for polymorphic types, check subsumption here,
431426-- change the definition of `binderRequiresMonotype`,
432427-- and use `kindOfWithScopedVars`.
@@ -480,14 +475,13 @@ checkBinders _ _ [] = return []
480475checkBinders nvals ret (CaseAlternative binders result : bs) = do
481476 guardWith (errorMessage $ OverlappingArgNames Nothing) $
482477 let ns = concatMap binderNames binders in length (nub ns) == length ns
483− Just moduleName <- checkCurrentModule <$> get
484478 m1 <- M.unions <$> zipWithM inferBinder nvals binders
485− r <- bindLocalVariables moduleName [ (name, ty, Defined) | (name, ty) <- M.toList m1 ] $
479+ r <- bindLocalVariables [ (name, ty, Defined) | (name, ty) <- M.toList m1 ] $
486480 CaseAlternative binders <$>
487481 case result of
488482 Left gs -> do
489483 gs' <- forM gs $ \(grd, val) -> do
490− grd' <- rethrow (addHint ErrorCheckingGuard) $ check grd tyBoolean
484+ grd' <- withErrorMessageHint ErrorCheckingGuard $ check grd tyBoolean
491485 val' <- TypedValue True <$> check val ret <*> pure ret
492486 return (grd', val')
493487 return $ Left gs'
@@ -505,7 +499,7 @@ check ::
505499 Expr ->
506500 Type ->
507501 m Expr
508−check val ty = rethrow (addHint (ErrorCheckingType val ty)) $ check' val ty
502+check val ty = withErrorMessageHint (ErrorCheckingType val ty) $ check' val ty
509503
510504-- |
511505-- Check the type of a value
@@ -574,8 +568,7 @@ check' (Literal (ArrayLiteral vals)) t@(TypeApp a ty) = do
574568 return $ TypedValue True array t
575569check' (Abs (Left arg) ret) ty@(TypeApp (TypeApp t argTy) retTy) = do
576570 unifyTypes t tyFunction
577− Just moduleName <- checkCurrentModule <$> get
578− ret' <- withBindingGroupVisible $ bindLocalVariables moduleName [(arg, argTy, Defined)] $ check ret retTy
571+ ret' <- withBindingGroupVisible $ bindLocalVariables [(arg, argTy, Defined)] $ check ret retTy
579572 return $ TypedValue True (Abs (Left arg) ret') ty
580573check' (Abs (Right _) _) _ = internalError "Binder was not desugared"
581574check' (App f arg) ret = do
@@ -583,9 +576,8 @@ check' (App f arg) ret = do
583576 (_, app) <- checkFunctionApplication f' ft arg (Just ret)
584577 return $ TypedValue True app ret
585578check' v@(Var var) ty = do
586− Just moduleName <- checkCurrentModule <$> get
587− checkVisibility moduleName var
588− repl <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< lookupVariable moduleName $ var
579+ checkVisibility var
580+ repl <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< lookupVariable $ var
589581 ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty
590582 v' <- subsumes (Just v) repl ty'
591583 case v' of
@@ -599,7 +591,8 @@ check' (SuperClassDictionary className tys) _ = do
599591 -- declaration gets desugared.
600592 -}
601593 dicts <- getTypeClassDictionaries
602− return $ TypeClassDictionary (Constraint className tys Nothing) dicts
594+ hints <- gets checkHints
595+ return $ TypeClassDictionary (Constraint className tys Nothing) dicts hints
603596check' (TypedValue checkType val ty1) ty2 = do
604597 Just moduleName <- checkCurrentModule <$> get
605598 (kind, args) <- kindOfWithScopedVars ty1
@@ -638,7 +631,7 @@ check' e@(ObjectUpdate obj ps) t@(TypeApp o row) | o == tyRecord = do
638631 obj' <- check obj (TypeApp tyRecord (rowFromList (us ++ remainingProps, rest)))
639632 ps' <- checkProperties e ps row True
640633 return $ TypedValue True (ObjectUpdate obj' ps') t
641−check' (Accessor prop val) ty = rethrow (addHint (ErrorCheckingAccessor val prop)) $ do
634+check' (Accessor prop val) ty = withErrorMessageHint (ErrorCheckingAccessor val prop) $ do
642635 rest <- freshType
643636 val' <- check val (TypeApp tyRecord (RCons prop ty rest))
644637 return $ TypedValue True (Accessor prop val') ty
@@ -659,7 +652,7 @@ check' val kt@(KindedType ty kind) = do
659652 checkTypeKind ty kind
660653 val' <- check' val ty
661654 return $ TypedValue True val' kt
662−check' (PositionedValue pos c val) ty = warnAndRethrowWithPosition pos $ do
655+check' (PositionedValue pos c val) ty = warnAndRethrowWithPositionTC pos $ do
663656 TypedValue t v ty' <- check' val ty
664657 return $ TypedValue t (PositionedValue pos c v) ty'
665658check' val ty = do
@@ -713,7 +706,7 @@ checkFunctionApplication ::
713706 Expr ->
714707 Maybe Type ->
715708 m (Type, Expr)
716−checkFunctionApplication fn fnTy arg ret = rethrow (addHint (ErrorInApplication fn fnTy arg)) $ do
709+checkFunctionApplication fn fnTy arg ret = withErrorMessageHint (ErrorInApplication fn fnTy arg) $ do
717710 subst <- gets checkSubstitution
718711 checkFunctionApplication' fn (substituteType subst fnTy) arg (substituteType subst <$> ret)
719712
@@ -749,7 +742,8 @@ checkFunctionApplication' fn (KindedType ty _) arg ret =
749742 checkFunctionApplication fn ty arg ret
750743checkFunctionApplication' fn (ConstrainedType constraints fnTy) arg ret = do
751744 dicts <- getTypeClassDictionaries
752− checkFunctionApplication' (foldl App fn (map (flip TypeClassDictionary dicts) constraints)) fnTy arg ret
745+ hints <- gets checkHints
746+ checkFunctionApplication' (foldl App fn (map (\cs -> TypeClassDictionary cs dicts hints) constraints)) fnTy arg ret
753747checkFunctionApplication' fn fnTy dict@TypeClassDictionary{} _ =
754748 return (fnTy, App fn dict)
755749checkFunctionApplication' _ fnTy arg _ = throwError . errorMessage $ CannotApplyFunction fnTy arg
src/Language/PureScript/TypeChecker/Unify.hs+9−5
@@ -80,7 +80,7 @@ unknownsInType t = everythingOnTypes (.) go t []
8080unifyTypes :: (MonadError MultipleErrors m, MonadState CheckState m) => Type -> Type -> m ()
8181unifyTypes t1 t2 = do
8282 sub <- gets checkSubstitution
83− rethrow (addHint (ErrorUnifyingTypes t1 t2)) $ unifyTypes' (substituteType sub t1) (substituteType sub t2)
83+ withErrorMessageHint (ErrorUnifyingTypes t1 t2) $ unifyTypes' (substituteType sub t1) (substituteType sub t2)
8484 where
8585 unifyTypes' (TUnknown u1) (TUnknown u2) | u1 == u2 = return ()
8686 unifyTypes' (TUnknown u) t = solveType u t
@@ -112,9 +112,11 @@ unifyTypes t1 t2 = do
112112 unifyTypes' r1 r2@RCons{} = unifyRows r1 r2
113113 unifyTypes' r1@REmpty r2 = unifyRows r1 r2
114114 unifyTypes' r1 r2@REmpty = unifyRows r1 r2
115− unifyTypes' ty1@(ConstrainedType _ _) ty2 = throwError . errorMessage $ ConstrainedTypeUnified ty1 ty2
115+ unifyTypes' ty1@(ConstrainedType _ _) ty2 =
116+ throwError . errorMessage $ ConstrainedTypeUnified ty1 ty2
116117 unifyTypes' t3 t4@(ConstrainedType _ _) = unifyTypes' t4 t3
117− unifyTypes' t3 t4 = throwError . errorMessage $ TypesDoNotUnify t3 t4
118+ unifyTypes' t3 t4 =
119+ throwError . errorMessage $ TypesDoNotUnify t3 t4
118120
119121-- |
120122-- Unify two rows, updating the current substitution
@@ -147,7 +149,8 @@ unifyRows r1 r2 =
147149 unifyRows' [] REmpty [] REmpty = return ()
148150 unifyRows' [] (TypeVar v1) [] (TypeVar v2) | v1 == v2 = return ()
149151 unifyRows' [] (Skolem _ s1 _ _) [] (Skolem _ s2 _ _) | s1 == s2 = return ()
150− unifyRows' _ _ _ _ = throwError . errorMessage $ TypesDoNotUnify r1 r2
152+ unifyRows' _ _ _ _ =
153+ throwError . errorMessage $ TypesDoNotUnify r1 r2
151154
152155-- |
153156-- Check that two types unify
@@ -195,7 +198,8 @@ replaceTypeWildcards = everywhereOnTypesM replace
195198 where
196199 replace (TypeWildcard ss) = do
197200 t <- freshType
198− warnWithPosition ss $ tell . errorMessage $ WildcardInferredType t
201+ ctx <- getLocalContext
202+ warnWithPosition ss $ tell . errorMessage $ WildcardInferredType t ctx
199203 return t
200204 replace other = return other
201205
src/Language/PureScript/TypeClassDictionaries.hs+2−2
@@ -21,7 +21,7 @@ data TypeClassDictionaryInScope
2121 -- | Type class dependencies which must be satisfied to construct this dictionary
2222 , tcdDependencies :: Maybe [Constraint]
2323 }
24− deriving (Show, Read)
24+ deriving (Show)
2525
2626-- |
2727-- A simplified representation of expressions which are used to represent type
@@ -44,4 +44,4 @@ data DictionaryValue
4444 -- A subclass dictionary
4545 --
4646 | SubclassDictionaryValue DictionaryValue (Qualified (ProperName 'ClassName)) Integer
47− deriving (Show, Read, Ord, Eq)
47+ deriving (Show, Ord, Eq)
src/Language/PureScript/Types.hs+4−4
@@ -23,7 +23,7 @@ import Language.PureScript.Names
2323-- An identifier for the scope of a skolem variable
2424--
2525newtype SkolemScope = SkolemScope { runSkolemScope :: Int }
26− deriving (Show, Read, Eq, Ord, A.ToJSON, A.FromJSON)
26+ deriving (Show, Eq, Ord, A.ToJSON, A.FromJSON)
2727
2828-- |
2929-- The type of types
@@ -71,7 +71,7 @@ data Type
7171 -- Note: although it seems this constructor is not used, it _is_ useful,
7272 -- since it prevents certain traversals from matching.
7373 | ParensInType Type
74− deriving (Show, Read, Eq, Ord)
74+ deriving (Show, Eq, Ord)
7575
7676-- | Additional data relevant to type class constraints
7777data ConstraintData
@@ -81,7 +81,7 @@ data ConstraintData
8181 -- not matched, and a flag indicating whether the list was truncated or not.
8282 -- Note: we use 'String' here because using 'Binder' would introduce a cyclic
8383 -- dependency in the module graph.
84− deriving (Show, Read, Eq, Ord)
84+ deriving (Show, Eq, Ord)
8585
8686-- | A typeclass constraint
8787data Constraint = Constraint
@@ -91,7 +91,7 @@ data Constraint = Constraint
9191 -- ^ type arguments
9292 , constraintData :: Maybe ConstraintData
9393 -- ^ additional data relevant to this constraint
94− } deriving (Show, Read, Eq, Ord)
94+ } deriving (Show, Eq, Ord)
9595
9696mapConstraintArgs :: ([Type] -> [Type]) -> Constraint -> Constraint
9797mapConstraintArgs f c = c { constraintArgs = f (constraintArgs c) }
stack-ghc-8.0.yaml+1−1
@@ -1,4 +1,4 @@
1−resolver: nightly-2016-05-29
1+resolver: nightly-2016-07-19
22packages:
33- '.'
44extra-deps:
stack.yaml+7−3
@@ -1,5 +1,9 @@
1−resolver: lts-6.1
1+resolver: lts-6.10
22packages:
33- '.'
4−extra-deps: []
5−flags: {}
4+extra-deps:
5+- aeson-1.0.0.0
6+- semigroups-0.18.2
7+flags:
8+ semigroups:
9+ bytestring-builder: false
tests/Language/PureScript/Ide/ImportsSpec.hs+1−1
@@ -3,7 +3,7 @@
33module Language.PureScript.Ide.ImportsSpec where
44
55import Protolude
6−import Unsafe (fromJust)
6+import Data.Maybe (fromJust)
77
88import qualified Language.PureScript as P
99import Language.PureScript.Ide.Imports
tests/Language/PureScript/Ide/Integration.hs+1−1
@@ -48,7 +48,7 @@ module Language.PureScript.Ide.Integration
4848 ) where
4949
5050import Protolude
51−import Unsafe (fromJust)
51+import Data.Maybe (fromJust)
5252
5353import Data.Aeson
5454import Data.Aeson.Types
tests/TestPscPublish.hs+1−1
@@ -30,7 +30,7 @@ data TestResult
3030 = ParseFailed String
3131 | Mismatch ByteString ByteString -- ^ encoding before, encoding after
3232 | Pass ByteString
33− deriving (Show, Read)
33+ deriving (Show)
3434
3535roundTrip :: UploadedPackage -> TestResult
3636roundTrip pkg =