typing: new attribute AExpr::implicit_cast_to
authorJean Privat <jean@pryen.org>
Fri, 7 Dec 2012 20:01:01 +0000 (15:01 -0500)
committerJean Privat <jean@pryen.org>
Fri, 7 Dec 2012 20:01:01 +0000 (15:01 -0500)
If required, the following implicit cast ".as(XXX)"
Such a cast may by required after evaluating the expression when
a unsafe operation is detected (silently accepted by the Nit language).

The attribute is computed by `check_subtype`

Signed-off-by: Jean Privat <jean@pryen.org>

src/typing.nit

index 8b91bab..a7e2aa5 100644 (file)
@@ -140,6 +140,9 @@ private class TypeVisitor
                if sup == null then return null # Forward error
 
                var res = check_subtype(nexpr, sub, sup)
+               if res != sub then
+                       nexpr.implicit_cast_to = res
+               end
                return res
        end
 
@@ -469,6 +472,12 @@ redef class AExpr
        # Used to distinguish errors and statements when `mtype' == null
        var is_typed: Bool = false
 
+       # If required, the following implicit cast ".as(XXX)"
+       # Such a cast may by required after evaluating the expression when
+       # a unsafe operation is detected (silently accepted by the Nit language).
+       # The attribute is computed by `check_subtype`
+       var implicit_cast_to: nullable MType = null
+
        # Return the variable read (if any)
        # Used to perform adaptive typing
        fun its_variable: nullable Variable do return null