Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 7dcbdd7

Browse files
committed
fix: conversions in Number->to_decimal
1 parent 9def8f0 commit 7dcbdd7

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

examples/code_challenges/flipped_bits.⭐

-13
This file was deleted.

src/cosmo/runtime/intrinsic/number.cr

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class Cosmo::Intrinsic::Numbers
8080
def call(args : Array(ValueType)) : Num
8181
t = token("Number->to_decimal")
8282
TypeChecker.assert("int", @_self, t)
83-
TypeChecker.assert("int", args.first, t)
84-
@_self.to_s.to_i(args.first.as Int)
83+
TypeChecker.assert("uint", args.first, t)
84+
@_self.to_s.to_i64(args.first.as Int)
8585
end
8686
end
8787

src/cosmo/runtime/type_checker.cr

+12-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,18 @@ module Cosmo::TypeChecker
181181
if value.is_a?(Bool)
182182
value ? 1 : 0
183183
else
184-
value.to_u64
184+
value.to_i64.to_u64
185+
end
186+
elsif is?(type.lexeme, 1_i128, type) && (
187+
value.is_a?(String) || value.is_a?(Char) ||
188+
value.is_a?(Float) || value.is_a?(Int) ||
189+
value.is_a?(Bool)
190+
) # if the type is an integer
191+
192+
if value.is_a?(Bool)
193+
value ? 1_i128 : 0_i128
194+
else
195+
value.to_i128
185196
end
186197
elsif is?(type.lexeme, 1, type) && (
187198
value.is_a?(String) || value.is_a?(Char) ||

0 commit comments

Comments
 (0)