You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the following example fails to compile (see nim-lang/Nim#17420):
typeComparable=conceptproccompare(a, b: Self): int# so that there are no conflicts with `cmp`proctest[T: Comparable](x, y: T) =echocompare(x, y) # Error: undeclared identifier: 'compare'
The reason is that the declarations in a concept body are not considered for name resolution. However, this would be very useful for defining concepts and functions that operate on types implementing the concept, without having such a type in scope.
Solution
Concepts define a dummy proc that is considered for name resolution. It wouldn't need to return anything useful, since it can only be called when the concept is implemented for the type it's called with anyway. This could either be done by generating a proc that just returns the default value of the return type (although this wouldn't work when you can define types without a default value, see #290 and #252) or by using compiler magic.
The text was updated successfully, but these errors were encountered:
Motivation
Currently, the following example fails to compile (see nim-lang/Nim#17420):
The reason is that the declarations in a concept body are not considered for name resolution. However, this would be very useful for defining concepts and functions that operate on types implementing the concept, without having such a type in scope.
Solution
Concepts define a dummy proc that is considered for name resolution. It wouldn't need to return anything useful, since it can only be called when the concept is implemented for the type it's called with anyway. This could either be done by generating a proc that just returns the
default
value of the return type (although this wouldn't work when you can define types without a default value, see #290 and #252) or by using compiler magic.The text was updated successfully, but these errors were encountered: