interfaces: fix mkMethod erasure (#12171)

We erase the call to `mkMethod` in `convertExpr` instead of pattern
matching against the binding. This fixes a bug when the method body
contained statements using typeclass dictionaries such as
`do [2] === [2]`.

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Robin Krom 2021-12-16 15:22:46 +01:00 committed by GitHub
parent 2940a7b5c2
commit 1ed02369eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 10 deletions

View File

@ -558,7 +558,7 @@ convertModule envLfVersion envEnableScenarios envPkgMap envStablePackages envIsG
envInterfaceMethodInstances = MS.fromListWith (++)
[
( (mod, mkTypeCon [getOccText iface], mkTypeCon [getOccText tpl])
, [(methodName, body)]
, [(methodName, untick val)]
)
| (name, val) <- binds
, TypeCon methodNewtype
@ -569,15 +569,6 @@ convertModule envLfVersion envEnableScenarios envPkgMap envStablePackages envIsG
] <- [varType name]
, NameIn DA_Internal_Desugar "Method" <- [methodNewtype]
, Just mod <- [nameModule_maybe (getName iface)]
, Var (NameIn DA_Internal_Desugar "mkMethod")
`App` Type _tpl
`App` Type _iface
`App` Type _methodName
`App` Type _methodType
`App` _implDict
`App` _hasMethodDict
`App` body
<- [untick val]
]
envChoiceData = MS.fromListWith (++)
[ (mkTypeCon [getOccText tplTy], [ChoiceData ty v])
@ -1220,6 +1211,9 @@ convertExpr env0 e = do
pure $ ETmLam (v, TStruct fields) $ ERecCon tupleType $ zipWithFrom mkFieldProj (1 :: Int) fields
go env (VarIn GHC_Types "primitive") (LType (isStrLitTy -> Just y) : LType t : args)
= fmap (, args) $ convertPrim (envLfVersion env) (unpackFS y) <$> convertType env t
-- erase mkMethod calls and leave only the body.
go env (VarIn DA_Internal_Desugar "mkMethod") (LType _tpl : LType _iface : LType _methodName : LType _methodTy : LExpr _implDict : LExpr _hasMethodDic : LExpr body : args)
= go env body args
go env (VarIn GHC_Types "primitiveInterface") (LType (isStrLitTy -> Just y) : LType t : args)
= do
ty <- convertType env t

View File

@ -73,6 +73,7 @@ template Asset
pure (toInterfaceContractId @Token cid)
let noopImpl = \nothing -> do
[1] === [1] -- make sure `mkMethod` calls are properly erased in the presence of polymorphism.
pure ()
main = scenario do