nitc: adaptive typing apply non-nullness when fallbacking
authorJean Privat <jean@pryen.org>
Fri, 10 Mar 2017 15:32:15 +0000 (10:32 -0500)
committerJean Privat <jean@pryen.org>
Fri, 10 Mar 2017 15:37:19 +0000 (10:37 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/semantize/typing.nit

index 9813284..0bbe61b 100644 (file)
@@ -580,7 +580,16 @@ private class TypeVisitor
                                return mtypes.first
                        else
                                var res = merge_types(node,mtypes)
-                               if res == null then res = variable.declared_type
+                               if res == null then
+                                       res = variable.declared_type
+                                       # Try to fallback to a non-null version
+                                       if res != null and can_be_null(res) then do
+                                               for t in mtypes do
+                                                       if t != null and can_be_null(t) then break label
+                                               end
+                                               res = res.as_notnull
+                                       end label
+                               end
                                return res
                        end
                end