syntax: while condition can now cast variable
authorJean Privat <jean@pryen.org>
Mon, 22 Jun 2009 18:19:12 +0000 (14:19 -0400)
committerJean Privat <jean@pryen.org>
Wed, 24 Jun 2009 19:48:18 +0000 (15:48 -0400)
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 <jean@pryen.org>

src/syntax/typing.nit
tests/base_isa_cast2.nit
tests/sav/base_isa_cast2.sav
tests/sav/base_isa_cast2_alt8.sav

index e7aa1a5..ec0a2f4 100644 (file)
@@ -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
index 14de354..ca13a66 100644 (file)
@@ -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
index 528a2bc..c2d6231 100644 (file)
@@ -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.