-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix macro interpreter Number type of arithmetic expressions #5972
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,8 +214,8 @@ module Crystal | |
def initialize(@value : String, @kind = :i32) | ||
end | ||
|
||
def initialize(value : Number, @kind = :i32) | ||
@value = value.to_s | ||
def self.new(value : Number) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not continue to accept There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this would be that useful. It's a simple API now: If the constructor receives a |
||
new(value.to_s, kind_from_number(value)) | ||
end | ||
|
||
def has_sign? | ||
|
@@ -243,6 +243,24 @@ module Crystal | |
|
||
def_equals value.to_f64, kind | ||
def_hash value, kind | ||
|
||
def self.kind_from_number(number : Number) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the only usage of Asking this because either make it protected/private or add Thank you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Atm it is the only usage, I don't know if it there is a different use case. Compiler types and methods are not really documented anyway, so there is not much gain from adding I don't think there are any particular guidelines about this for the compiler. |
||
case number | ||
when Int8 then :i8 | ||
when Int16 then :i16 | ||
when Int32 then :i32 | ||
when Int64 then :i64 | ||
when Int128 then :i128 | ||
when UInt8 then :u8 | ||
when UInt16 then :u16 | ||
when UInt32 then :u32 | ||
when UInt64 then :u64 | ||
when UInt128 then :u128 | ||
when Float32 then :f32 | ||
when Float64 then :f64 | ||
else raise "Unsupported Number type for NumberLiteral: #{number.class}" | ||
end | ||
end | ||
end | ||
|
||
# A char literal. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few line above the value is converted to an
Int64
(@value.to_i64?
), it feels weird to 'cast' it to:i32
here, is it intentional ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is intentional as far as this prevents codegen to fail. 🤷♂️ It's only a workaround, though.
In fact, this isn't even a change: it implicitly was
:i32
before, now it's just explicit.But yes, it should probably be adjusted, however we need to fix the codegen bug first.