niti: implements lazy in the getter using isset
authorJean Privat <jean@pryen.org>
Mon, 21 Jul 2014 20:19:15 +0000 (16:19 -0400)
committerJean Privat <jean@pryen.org>
Tue, 22 Jul 2014 11:58:09 +0000 (07:58 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/naive_interpreter.nit

index 431d02b..138c7e2 100644 (file)
@@ -991,7 +991,8 @@ redef class AAttrPropdef
                var attr = self.mpropdef.mproperty
                if mpropdef == mreadpropdef then
                        assert args.length == 1
-                       return v.read_attribute(attr, recv)
+                       if not is_lazy or v.isset_attribute(attr, recv) then return v.read_attribute(attr, recv)
+                       return evaluate_expr(v, recv)
                else if mpropdef == mwritepropdef then
                        assert args.length == 2
                        v.write_attribute(attr, recv, args[1])
@@ -1004,6 +1005,7 @@ redef class AAttrPropdef
        # Evaluate and set the default value of the attribute in `recv`
        private fun init_expr(v: NaiveInterpreter, recv: Instance)
        do
+               if is_lazy then return
                var nexpr = self.n_expr
                if nexpr != null then
                        evaluate_expr(v, recv)