Merge: Infer more attribute types
authorJean Privat <jean@pryen.org>
Fri, 16 Feb 2018 16:45:45 +0000 (11:45 -0500)
committerJean Privat <jean@pryen.org>
Fri, 16 Feb 2018 16:45:45 +0000 (11:45 -0500)
commitb4e876e28a4622b7bc72eed0f1f9630f576de881
treecf886d5b310d1d4bd7c269557d1bc1a965f8c8af
parent55f6fef06bba4ab8abbd47128359d8448c61e3c0
parent72741c14a278c4c533983b4c474aee9794566763
Merge: Infer more attribute types

Extend the detection of the static type of attributes from their literal values to support three new cases:

* Simple arrays like `[0, 1, 2]` and `[new Set[Int], new Set[Int]]`. However, it does not accept arrays with an explicit type because we can't subtype/anchor at that point, as far as I know.

* Negative integers and floats. This cheats a bit as the return type of the unary - is defined in the core libary. However this should help 99.9% of the time, in particular for Nit beginners, and a workaround is to declare the attribute static type when defining a different kernel library.

* The `once` keyword.

~~~
class A
       # Now detected
       var i = -1
       var f = -1.0
       var a = [0, 1]
       var o = once [0, 1]

       # These are refused
       var a1 = [0, 1.0, "a"] # Different types
       var a2 = [0, 1: Int] # Can't reliably check subtypes
       var a4 = [1+1] # Expression
       var o1 = once [0, "a"] # Forwarded error
end
~~~

---

You may want to review commit by commit as the first commit is a small refactoring.

Pull-Request: #2614