michaelmmacleod
2019-5-2 02:00:56

soegaard2
2019-5-2 04:38:40

@michaelmmacleod What is the observed behavior?


soegaard2
2019-5-2 04:39:49

(rereading - get it now - the program runs without errors)


soegaard2
2019-5-2 04:41:05

The docs say: “External contracts govern behavior when an object is instantiated from a class or when methods or fields are accessed via an object of that class. ”


soegaard2
2019-5-2 04:41:34

Also: “Methods and fields listed in an absent clause must not be present in the class.”


soegaard2
2019-5-2 04:44:02

So, I think, since class/c optionally has an absent clause, but no present clause, that you won’t get an error when a field is missing from the init section.


soegaard2
2019-5-2 04:47:07

The docs doesn’t mention what happens when a field is missing, though:


soegaard2
2019-5-2 04:47:17

An initialization argument contract, tagged with init, describes the expected behavior of the value paired with that name during class instantiation. The same name can be provided more than once, in which case the first such contract in the class/c form is applied to the first value tagged with that name in the list of initialization arguments, and so on.


soegaard2
2019-5-2 04:50:47

It’s not unreasonable to expect an error though - but is it possible to detect the error at compile time?


soegaard2
2019-5-2 04:51:11

The values bound to initialization variables are - the arguments provided with instantiate or passed to make-object, if the object is created as a direct instance of the class; or, - the arguments passed to the superclass initialization form or procedure, if the object is created as an instance of a derived class.


michaelmmacleod
2019-5-2 05:22:22

Thanks @soegaard2. I don’t know much at all about the internal representation of objects and classes, but it would make sense to me that this would be the kind of thing that Racket couldn’t detect at compile time. The problem popped up when I removed some initialization fields from a class and forgot to update their contracts—I was surprised that my code compiled when I realized my mistake.