Cannot use math.`^` with non-int types. #4574

Closed
mathsaey opened this Issue Aug 5, 2016 · 1 comment

Projects

None yet

1 participant

@mathsaey
Contributor
mathsaey commented Aug 5, 2016

The following code:

import math

let
  x: uint = 5
  err = x ^ 2
  works = int(x) ^ 2`

Does not compile with the following error:

unt.nim(5, 11) template/generic instantiation from here
lib/system.nim(347, 5) Error: type mismatch: got (int literal(0), uint)
but expected one of:
proc `<=`[Enum: enum](x, y: Enum): bool
proc `<=`(x, y: string): bool
proc `<=`(x, y: char): bool
proc `<=`[T](x, y: set[T]): bool
proc `<=`(x, y: bool): bool
proc `<=`[T](x, y: ref T): bool
proc `<=`(x, y: pointer): bool
proc `<=`[T: SomeUnsignedInt](x, y: T): bool
proc `<=`(x, y: float32): bool
proc `<=`(x, y: int64): bool
proc `<=`(x, y: int32): bool
proc `<=`(x, y: int): bool
proc `<=`[T: tuple](x, y: T): bool
proc `<=`(x, y: int16): bool
proc `<=`(x, y: int8): bool
proc `<=`(x, y: float): bool

This is the case since the math module performs the following assertion: assert y >= 0 which does not seem to work when y is of a non-int type.

@mathsaey
Contributor
mathsaey commented Aug 5, 2016

I fixed it and sent a pull request: #4575

@Araq Araq pushed a commit that closed this issue Aug 5, 2016
@mathsaey mathsaey Fixed #4574 2a84206
@Araq Araq closed this in 2a84206 Aug 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment