-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation request about int #12552
Comments
I'm not sure the documentation is to blame here, looks to me like a compiler bug. |
This may be a bug, but I think it is also a, or rather two, documentation issues. The first issue is that to my reading of the documentation the compiler follows the letter, The second issue is the lack of a link to the RFCs on the documentation home page, which Part of the issue seems to be the int literal problem described by GULPF on 3 Apr 2018 in RFC #36. One of the practical implications of the problem is that refactoring of a compile-time dispatch proc blah[T](x : T) =
when x is SomeSignedInt:
blahInt(x)
elif x is SomeUnsignedInt:
blahUint(x)
elif ... into overloaded procedures [or any other use of [Newbie question: is there any advantage to using the dispatch table approach in Nim that I am missing?] |
I would say this is a bug. The call to The behavior is correct for converters: converter foo(x: int): string = $x
proc bar[T: string](n: T) =
echo "bar: ", n, " is of type ", typeof(n)
bar(123)
# bar: 123 is of type string But not floats with literals (although this might require a separate fix): proc bar[T: float](n: T) =
echo "bar: ", n, " is of type ", typeof(n)
bar(123)
# bar: 123 is of type int |
fixes nim-lang#4858, fixes nim-lang#10027, fixes nim-lang#12552, fixes nim-lang#15721, fixes nim-lang#21331, refs nim-lang#1214, follows up nim-lang#24216, split from nim-lang#24198
Would it be possible to document when
int
behaves as atype
and whenint
behaves as a
type class
.The differences between the two have some profound and perhaps unexpected
implications for Nim programs.
For the casual reader it is difficult if not impossible to find an answer to
the question in the documentation.
Consider the following examples:
i.e. in
proc bar[T : int] (n : T)
,int
behaves likeint | int8 | int16 | int32
(with some magic - see barfoo and barfoofoo below)However, this behaviour does not carry through to overloading resolution
or when
int
appears as part of a type expressionThe fact that
int
isint | int8 | int16 | int32
"with magic" is demonstrated by the fact thatfails, while
works as one would expect, but obviously not for int64 :
The text was updated successfully, but these errors were encountered: