Skip to content

AboutNumbers wrong types #474

Description

@magoerlich

https://github.com/vexx32/PSKoans/blob/1317701a7d2bf6ca7efff0eb21d3a3d0478740e9/PSKoans/Koans/Introduction/AboutNumbers.Koans.ps1#L94-L99

Is this part correct about numbers getting converted to longs?

Because no matter, what I try for me it's always a double

Code:

$BigValue = [int]::MaxValue + 200
$BigValue | Should -BeOfType [long]
$BigValue | Should -BeGreaterThan $MaxValue

Output:

Expected the value to have type [long] or any of its subtypes, but got 2147483847 with type [double].

Starting with a short and increasing it to >MaxValue behaves the same:

~\PSKoans
❯ $int = [int]::MaxValue

~\PSKoans
❯ $int.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Int32                                    System.ValueType


~\PSKoans
❯ $int += 100

~\PSKoans
❯ $int.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Double                                   System.ValueType

Activity

  1. jrwarwick commented on Mar 2, 2023

    @jrwarwick

    Although your observation is correct, there is some obfuscation involved. Essentially "Long" is an alias for the underlying actual datatype.
    Refer to this page on "Numeric Type Accelerators": https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_numeric_literals?view=powershell-7.3#numeric-type-accelerators
    I would expect the -BeOfType parameter to handle this, and indeed it seems to on my install of PSKoans.

  2. indented-automation commented on Mar 2, 2023

    @indented-automation
    Contributor
  3. added theissue type on Sep 16, 2026
  4. added this to the Future milestone on Sep 16, 2026
  5. removed this from the Future milestone on Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions