@@ -45,6 +45,8 @@ import qualified Language.PureScript.Constants as C
4545data Evidence
4646 = NamedInstance (Qualified Ident )
4747 -- ^ An existing named instance
48+ | WarnInstance Type
49+ -- ^ Computed instance of the Warn type class with a user-defined warning message
4850 | IsSymbolInstance PSString
4951 -- ^ Computed instance of the IsSymbol type class for a given Symbol literal
5052 | CompareSymbolInstance
@@ -144,6 +146,8 @@ entails SolverOptions{..} constraint context hints =
144146 solve constraint
145147 where
146148 forClassName :: InstanceContext -> Qualified (ProperName 'ClassName) -> [Type ] -> [TypeClassDict ]
149+ forClassName _ C. Warn [msg] =
150+ [TypeClassDictionaryInScope (WarnInstance msg) [] C. Warn [msg] Nothing ]
147151 forClassName _ C. IsSymbol [TypeLevelString sym] =
148152 [TypeClassDictionaryInScope (IsSymbolInstance sym) [] C. IsSymbol [TypeLevelString sym] Nothing ]
149153 forClassName _ C. CompareSymbol [arg0@ (TypeLevelString lhs), arg1@ (TypeLevelString rhs), _] =
@@ -216,8 +220,9 @@ entails SolverOptions{..} constraint context hints =
216220 let subst'' = fmap (substituteType currentSubst') subst'
217221 -- Solve any necessary subgoals
218222 args <- solveSubgoals subst'' (tcdDependencies tcd)
223+ initDict <- lift . lift $ mkDictionary (tcdValue tcd) args
219224 let match = foldr (\ (superclassName, index) dict -> subclassDictionaryValue dict superclassName index)
220- (mkDictionary (tcdValue tcd) args)
225+ initDict
221226 (tcdPath tcd)
222227 return match
223228 Unsolved unsolved -> do
@@ -308,15 +313,18 @@ entails SolverOptions{..} constraint context hints =
308313 Just <$> traverse (go (work + 1 ) . mapConstraintArgs (map (replaceAllTypeVars (M. toList subst)))) subgoals
309314
310315 -- Make a dictionary from subgoal dictionaries by applying the correct function
311- mkDictionary :: Evidence -> Maybe [Expr ] -> Expr
312- mkDictionary (NamedInstance n) args = foldl App (Var n) (fold args)
316+ mkDictionary :: Evidence -> Maybe [Expr ] -> m Expr
317+ mkDictionary (NamedInstance n) args = return $ foldl App (Var n) (fold args)
318+ mkDictionary (WarnInstance msg) _ = do
319+ tell . errorMessage $ UserDefinedWarning msg
320+ return $ TypeClassDictionaryConstructorApp C. Warn (Literal (ObjectLiteral [] ))
313321 mkDictionary (IsSymbolInstance sym) _ =
314322 let fields = [ (" reflectSymbol" , Abs (Left (Ident C. __unused)) (Literal (StringLiteral sym))) ] in
315- TypeClassDictionaryConstructorApp C. IsSymbol (Literal (ObjectLiteral fields))
323+ return $ TypeClassDictionaryConstructorApp C. IsSymbol (Literal (ObjectLiteral fields))
316324 mkDictionary CompareSymbolInstance _ =
317- TypeClassDictionaryConstructorApp C. CompareSymbol (Literal (ObjectLiteral [] ))
325+ return $ TypeClassDictionaryConstructorApp C. CompareSymbol (Literal (ObjectLiteral [] ))
318326 mkDictionary AppendSymbolInstance _ =
319- TypeClassDictionaryConstructorApp C. AppendSymbol (Literal (ObjectLiteral [] ))
327+ return $ TypeClassDictionaryConstructorApp C. AppendSymbol (Literal (ObjectLiteral [] ))
320328
321329 -- Turn a DictionaryValue into a Expr
322330 subclassDictionaryValue :: Expr -> Qualified (ProperName a ) -> Integer -> Expr
0 commit comments