nitlang / nit

Nit language
http://nitlanguage.org
Apache License 2.0
244 stars 67 forks source link

Contract refactoring #2827

Closed Delja closed 4 years ago

Delja commented 4 years ago

This pr do the following changes:

module one
import two
[...]

module two
import three

redef class C
    # Now all calls to foo of c (only in module one or two) check the `expect` property defined in module three (as defined by the default contract rule). 
    redef foo ...
end

module three

class C
    fun foo is expect(true), ensure(true)
end
class A
    fun foo(i: Int) is expect(i > 0) do end
end

var a = new A
a.foo(0)

This is the output of the program

Runtime error: Assert 'expect(i > 0)' failed