Skip to content

Array element types not inferred from array.apply #8

Description

@Brain-dawg

Understandably esoteric and might be out of scope, reporting anyway.

Something like

local test = array( 10, null ).apply( @( val, i ) val = i )

Results in the type system still assuming the array elements are null rather than integer or integer|null

Noticed when doing this trick to get floats from a KVString

local origin = split( config.leaderboard_cam, " " ).apply( @( str ) str.tofloat() )
// expected 'float', got 'string' warning
leaderboard_cam_pos = Vector( origin[0], origin[1], origin[2] )

I imagine trying to support every modify-in-place mutation for arrays/tables would be messy and annoying, and possibly undermines the point of type checking in the first place if gone too far. For specifically in-line array declaration + apply trickery like this though, maybe the apply funcs return value could be used for type inference instead.

If out of scope, is there a way to explicitly override variable types with a Tag?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions