4 ms·
I don't get why the compiler should have to check if the type set is non-empty. The compiler only has to check when the generic type/func is used if the concret
by dolmen 4y ago
I don't get why the compiler should have to check if the type set is non-empty.
The compiler only has to check when the generic type/func is used if the concrete type matches the type set. At worse the developer has written generic code that nobody can use.
Checking type sets is a work for a linter. But the developer should have caught the problem with a simple unit test.
I'm glad that the specification relieves the compiler writers from that the non-empty check task.
- dolmen 4y agoI want type check to be fast, directly in my editor. Linting can happen asynchronously in CI.
- Merovius 4y agoThere are two reason why the compiler would need to check: 1. Because it makes for a better developer experience, if you get early feedback about your code being wrong. And 2. because type-checking a generic function requires you to check that an operation is allowed for all types in a type set. If you write func F[T C](a, b T) T { return a + b }, the compiler needs to check that all types in C have a + operator. If the type set of C is empty, then that's true - all types in the empty set have the + operator.