diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-02-13 21:03:00 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-02-13 21:03:00 +0100 |
commit | 14efffc66cb60465c18c984311bde5a5502803db (patch) | |
tree | 72ce535da6c6f7c7851b49547030bc15de6620c6 | |
parent | d67825ea3f441523e2814b831d397d95c0dc46a4 (diff) |
Evaluate functions in parameters via unifyExpr
-rw-r--r-- | src/Parser/Expr.hs | 9 | ||||
-rw-r--r-- | src/Test.hs | 1 |
2 files changed, 4 insertions, 6 deletions
diff --git a/src/Parser/Expr.hs b/src/Parser/Expr.hs index d59e0b2..bc16149 100644 --- a/src/Parser/Expr.hs +++ b/src/Parser/Expr.hs @@ -391,18 +391,17 @@ recordSelector (SomeExpr expr) = do checkFunctionArguments :: FunctionArguments SomeArgumentType -> Int -> Maybe ArgumentKeyword -> SomeExpr -> TestParser SomeExpr -checkFunctionArguments (FunctionArguments argTypes) poff kw expr = do +checkFunctionArguments (FunctionArguments argTypes) poff kw sexpr@(SomeExpr expr) = do case M.lookup kw argTypes of Just (SomeArgumentType (_ :: ArgumentType expected)) -> do - withRecovery registerParseError $ do - void $ unify poff (ExprTypePrim (Proxy @expected)) (someExprType expr) - return expr + withRecovery (\e -> registerParseError e >> return sexpr) $ do + SomeExpr <$> unifyExpr poff (Proxy @expected) expr Nothing -> do registerParseError $ FancyError poff $ S.singleton $ ErrorFail $ T.unpack $ case kw of Just (ArgumentKeyword tkw) -> "unexpected parameter with keyword `" <> tkw <> "'" Nothing -> "unexpected parameter" - return expr + return sexpr functionArguments :: (Int -> Maybe ArgumentKeyword -> a -> TestParser b) -> TestParser a -> TestParser a -> (Int -> Text -> TestParser a) -> TestParser (FunctionArguments b) diff --git a/src/Test.hs b/src/Test.hs index 0f65b3c..82303f8 100644 --- a/src/Test.hs +++ b/src/Test.hs @@ -529,7 +529,6 @@ exprArgs = \case funFromSomeVarValue :: forall a m. (ExprType a, MonadFail m) => SourceLine -> FqVarName -> SomeVarValue -> m (FunctionType a) funFromSomeVarValue sline name (SomeVarValue (VarValue _ args value :: VarValue b)) = do maybe (fail err) return $ do - guard $ not $ anull args FunctionType <$> cast (value sline) where err = T.unpack $ T.concat [ T.pack "expected function returning ", textExprType @a Proxy, T.pack ", but variable '", textFqVarName name, T.pack "' has ", |