Closed Angeldude closed 7 years ago
Further investigations have allowed me to figure out ways of making the above examples work as expected. The class A example will work if I define the type signature of the method m, like this:
class A
extend RDL::Annotate
type '() -> Integer', typecheck: :now
var_type :@f, 'Integer'
def m
@f = 3 # type safe
@f = "three" # type error, incompatible type in assignment
@g = 42 # type error, no var_type for @g
end
end
This will then trigger the type errors in the instance variable. For the first example, the variable type will only work from within a method and, again, the method's type signature has to be present.
class ...
type '() -> Integer', typecheck: :now
def m
RDL.var_type :x, 'Integer'
x = 3
x = "three"
5
end
...
My question is, should this be reflected in the README or is what the README depicts the desired behavior? Again, I have not found a way to make the examples as originally depicted produce the type errors.
Right, RDL only typechecks the bodies of methods that have type signatures. It ignores any other code. I'll edit the documentation to make this more clear.
Hi everyone, maybe I'm misunderstanding or misinterpreting the README but all the type variable examples don't produce any type errors for me. For example
This does not give me any type errors, it behaves like regular ruby.
Same for this one:
Although the
attr_accessor_type
and other attribute methods do report type errors.