Merge: Use `as` casts to implicitly type class attributes
authorJean Privat <jean@pryen.org>
Tue, 8 Dec 2015 21:18:48 +0000 (16:18 -0500)
committerJean Privat <jean@pryen.org>
Tue, 8 Dec 2015 21:18:48 +0000 (16:18 -0500)
Until now, implicit types for class attributes are defined by literal types or new calls. This PR extends the support to `as` casts. So when an expression setting an attribute ends with a cast such as `.as(String)`, we can safely define the type of the attribute as `String`.

~~~
class A
    # Before
    var s: String = data_store["s"].as(String)

    # After
    var s = data_store["s"].as(String)
end
~~~

I did not modify the error messages by choice, to avoid making more complex the already long error messages with a rare use case. Also since `as` casts are unsafe by definition, I would not recommend to abuse this feature.

This does not apply to `as(not null)`.

Pull-Request: #1880
Reviewed-by: Jean Privat <jean@pryen.org>


Trivial merge