次のようなプログラムがランタイムにエラーする:
main = print (1 / 2)
エラーの様子は次のとおり:
$ ./trun testcases/defaultdouble.hs
# 1. tcompile
source file: testcases/defaultdouble.hs
dst dir: /defaultdouble
doCompile ... warning: kiexpr' :AppTy (Tycon (Name {origName = "Ratio", namePos = (265,17), isConName = True})) (Tycon (Name {origName = "Integer", namePos = (265,23), isConName = True})) []
warning: kiexpr' :AppTy (Tycon (Name {origName = "Ratio", namePos = (265,17), isConName = True})) (Tycon (Name {origName = "Integer", namePos = (265,23), isConName = True})) []
done.
implicitPrelude ... done.
doCompile ... warning: kiexpr' :AppTy (Tycon (Name {origName = "Ratio", namePos = (265,17), isConName = True})) (Tycon (Name {origName = "Integer", namePos = (265,23), isConName = True})) []
warning: kiexpr' :AppTy (Tycon (Name {origName = "Ratio", namePos = (265,17), isConName = True})) (Tycon (Name {origName = "Integer", namePos = (265,23), isConName = True})) []
done.
# 2. jout/compile
#!/bin/bash -v
target=$1
d=`dirname $1`
s=":"
if [ -d /c ]; then
s=";"
fi
javac -J-Duser.language=en -cp "../../brt/src$s$d" $target
defaultdouble/Main.java:10: error: cannot find symbol
Expr t4 = (Expr) new AtomExpr(new Dict(new Dict_36_Prelude_46_Integer_64_Prelude_46_Fractional()));
^
symbol: class Dict_36_Prelude_46_Integer_64_Prelude_46_Fractional
location: class Main
1 error
これは、現状では型検査器においては Num から Double への defaulting に対応しているのにたいして、後段の DictPass で対応していないことが原因と思われる。
(これは正確には「ランタイム」のエラーではないですね。java コンパイルの段階でエラーしている)
ひとまず、DictPass が未対応である間は Double への defaulting をしないよう、型検査器の方も変更しておく:
--- a/compiler/src/Typing.hs
+++ b/compiler/src/Typing.hs
@@ -157,7 +157,7 @@ modify ce@ClassEnv{ceMap = m} i c = ce{ceMap = insert i c m}
initialEnv :: ClassEnv
initialEnv = ClassEnv { ceMap = empty
- , defaults = [tInteger, tDouble]}
+ , defaults = [tInteger]}
type EnvTransformer = ClassEnv -> Maybe ClassEnv
これで、defaultdouble.hs は型検査でエラーするようになった:
bunnyc: cannot resolve ambiguity: [(Tyvar "v8093" Star,[IsIn "Prelude.Fractional" (TVar (Tyvar "v8093" Star))])]
全件確認中:
$ runhaskell t117.hs 0.5 unno@unno-FMVD70GN7G ~/work/bissues/117 $ ~/prj/bunny/compiler/bin/bunny testrun t117.hs /home/unno/prj/bunny/compiler/bin/bunnyc -d ./jout/t117 --xno-implicit-prelude /home/unno/prj/bunny/compiler/bin/../lib/Prelude.hs /home/unno/prj/bunny/compiler/bin/bunnyc -d ./jout/t117 --xlibrary-path /home/unno/prj/bunny/compiler/bin/../lib t117.hs bunnyc: cannot resolve ambiguity: [(Tyvar "v8777" Star,[IsIn "Prelude.Fractional" (TVar (Tyvar "v8777" Star))])] testrun: failed to compile t117.hs unno@unno-FMVD70GN7G ~/work/bissues/117 $ cat t117.hs main = print (1 /2)