rescript-lang / rescript-compiler

The compiler for ReScript.
https://rescript-lang.org
Other
6.74k stars 448 forks source link

Enhancement: Compiler warning when a non-shared data type is used with external #4499

Closed johnridesabike closed 4 years ago

johnridesabike commented 4 years ago

A common pitfall I've noticed is when people try to use a non-shared data type with external. This usually happens when they try to use list instead of array or a variant when they're trying to use a union type. Would it be possible for the compiler to check if any types in an external aren't on the shared data type list and emit a warning if they aren't?

I imagine this would make BuckleScript more beginner friendly, since type errors with externals are frustrating to debug. However, one possible downside I can imagine is how well the compiler can handle abstract types, especially since abstract types can be very useful with externals.

bobzhang commented 4 years ago

This is more complex than it sounds. Since in OCaml you can alias types and pass around. We can do some basic checks but not sure how valuable it is

bobzhang commented 4 years ago

closed since there's not a perfect solution