motoko icon indicating copy to clipboard operation
motoko copied to clipboard

Type inference bug?

Open crusso opened this issue 5 years ago • 2 comments

let t = 1;
let u = t; //ok
class C() {
  let v = t; //cannot infer type of forward variable t
};

crusso avatar Mar 12 '20 17:03 crusso

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.

rossberg avatar Apr 23 '20 14:04 rossberg

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)

crusso avatar Apr 23 '20 15:04 crusso