motoko
motoko copied to clipboard
Type inference bug?
let t = 1;
let u = t; //ok
class C() {
let v = t; //cannot infer type of forward variable t
};
This is actually expected. In the outer block, you first need to gather all type definitions. For classes without an annotation, that requires inferring the type of the body.
I suppose one could hack around to make this succeed in more cases (like here, where v does not contribute to the type C). But that would probably be very ad-hoc.
Perhaps, but even then, the error message is a bit weird since t is actually declared before v, so this isn't a forward reference to t (IMO)