syntax: real variable type evolution on IfexprExpr
authorJean Privat <jean@pryen.org>
Fri, 8 Jan 2010 21:56:12 +0000 (16:56 -0500)
committerJean Privat <jean@pryen.org>
Thu, 14 Jan 2010 16:43:40 +0000 (11:43 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/syntax/typing.nit

index f9fb4a6..840ed5e 100644 (file)
@@ -778,15 +778,24 @@ redef class AIfexprExpr
                v.use_if_true_variable_ctx(n_expr)
 
                # Process 'then'
+               v.variable_ctx = v.variable_ctx.sub(n_then)
                v.enter_visit(n_then)
 
+               # Remember what appened in the 'then'
+               var then_var_ctx = v.variable_ctx
+
                # Prepare 'else' context
                v.variable_ctx = old_var_ctx
                v.use_if_false_variable_ctx(n_expr)
 
                # Process 'else'
+               v.variable_ctx = v.variable_ctx.sub(n_else)
                v.enter_visit(n_else)
 
+               # Merge 'then' and 'else' contexts
+               old_var_ctx.merge2(then_var_ctx, v.variable_ctx, v.base_variable_ctx)
+               v.variable_ctx = old_var_ctx
+
                var stype = v.check_conform_multiexpr(null, [n_then, n_else])
                if stype == null then return