From 264fd697a626adb8a21d4d497b2be5a9b2aa51cf Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Mon, 22 Jun 2009 14:19:12 -0400 Subject: [PATCH] syntax: while condition can now cast variable Example: var a = foo # foo gives a A # Before the while, the base static type of a is set to A while a isa B do a.some_b_stuff # OK, since a isa B a = foo # OK, since 'base' static type of a is A end Signed-off-by: Jean Privat --- src/syntax/typing.nit | 14 ++++++++++++-- tests/base_isa_cast2.nit | 2 +- tests/sav/base_isa_cast2.sav | 1 + tests/sav/base_isa_cast2_alt8.sav | 1 - 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/syntax/typing.nit b/src/syntax/typing.nit index e7aa1a5..ec0a2f4 100644 --- a/src/syntax/typing.nit +++ b/src/syntax/typing.nit @@ -477,9 +477,19 @@ redef class AWhileExpr v.base_variable_ctx = v.variable_ctx v.variable_ctx = v.variable_ctx.sub(self) - super - + # Process condition + v.visit(n_expr) v.check_conform_expr(n_expr, v.type_bool) + + # Prepare inside context (assert cond) + v.use_if_true_variable_ctx(n_expr) + + # Process inside + if n_block != null then + v.variable_ctx = v.variable_ctx.sub(n_block) + v.visit(n_block) + end + v.variable_ctx = old_var_ctx v.base_variable_ctx = old_base_var_ctx v.escapable_ctx.pop diff --git a/tests/base_isa_cast2.nit b/tests/base_isa_cast2.nit index 14de354..ca13a66 100644 --- a/tests/base_isa_cast2.nit +++ b/tests/base_isa_cast2.nit @@ -47,7 +47,7 @@ end a.foo(4) a = a0 while a isa B do - #alt8#a.foo(5) + a.foo(5) a = new A #alt5#a.foo(-5) end diff --git a/tests/sav/base_isa_cast2.sav b/tests/sav/base_isa_cast2.sav index 85221a6..b414108 100644 --- a/tests/sav/base_isa_cast2.sav +++ b/tests/sav/base_isa_cast2.sav @@ -2,4 +2,5 @@ 2 3 4 +5 6 diff --git a/tests/sav/base_isa_cast2_alt8.sav b/tests/sav/base_isa_cast2_alt8.sav index 528a2bc..c2d6231 100644 --- a/tests/sav/base_isa_cast2_alt8.sav +++ b/tests/sav/base_isa_cast2_alt8.sav @@ -1,2 +1 @@ -alt/base_isa_cast2_alt8.nit:50,2--8: Error: Method 'foo' doesn't exists in A. alt/base_isa_cast2_alt8.nit:62,1--7: Error: Method 'foo' doesn't exists in A. -- 1.7.9.5