this repo has no description

Make div return float

Make type inference match run-time behavior. Add tests.

authored by bernsteinbear.com and committed by

Max Bernstein 7080f5a0 bd84f476

+9 -2
+9 -2
scrapscript.py
··· 3060 3060 3061 3061 3062 3062 class EndToEndTestsBase(unittest.TestCase): 3063 - def _run(self, text: str, env: Optional[Env] = None) -> Object: 3063 + def _run(self, text: str, env: Optional[Env] = None, check: bool = False) -> Object: 3064 3064 tokens = tokenize(text) 3065 3065 ast = parse(tokens) 3066 + if check: 3067 + infer_type(ast, OP_ENV) 3066 3068 if env is None: 3067 3069 env = boot_env() 3068 3070 return eval_exp(env, ast) ··· 3526 3528 ), 3527 3529 Int(7), 3528 3530 ) 3531 + 3532 + def test_int_div_returns_float(self) -> None: 3533 + self.assertEqual(self._run("1 / 2 + 3"), Float(3.5)) 3534 + with self.assertRaisesRegex(InferenceError, "int and float"): 3535 + self._run("1 / 2 + 3", check=True) 3529 3536 3530 3537 3531 3538 class ClosureOptimizeTests(unittest.TestCase): ··· 5697 5704 "+": Forall([], func_type(IntType, IntType, IntType)), 5698 5705 "-": Forall([], func_type(IntType, IntType, IntType)), 5699 5706 "*": Forall([], func_type(IntType, IntType, IntType)), 5700 - "/": Forall([], func_type(IntType, IntType, IntType)), 5707 + "/": Forall([], func_type(IntType, IntType, FloatType)), 5701 5708 "++": Forall([], func_type(StringType, StringType, StringType)), 5702 5709 ">+": Forall([TyVar("a")], func_type(TyVar("a"), list_type(TyVar("a")), list_type(TyVar("a")))), 5703 5710 "+<": Forall([TyVar("a")], func_type(list_type(TyVar("a")), TyVar("a"), list_type(TyVar("a")))),