Skip to content
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

[BUG] InlineArray does not permit size of 0 #3927

Open
samufi opened this issue Jan 6, 2025 · 0 comments
Open

[BUG] InlineArray does not permit size of 0 #3927

samufi opened this issue Jan 6, 2025 · 0 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@samufi
Copy link

samufi commented Jan 6, 2025

Bug description

[This may also be seen as a feature request]

The size parameter of the InlineArray is constrained to numbers of at least 1. I am sure this is intentional, as it may make little sense to create zero-size array. However, this blocks some common use cases when working with parameterized functions.

Steps to reproduce

Consider the following example:

from collections import InlineArray
from sys.info import sizeof

trait WritableCollectionElement(Writable, CollectionElement):
  pass

fn get_sizes[*Ts: AnyType]() -> InlineArray[Int, len(VariadicList(Ts))]:
  alias length = len(VariadicList(Ts))
  result = InlineArray[Int, len(VariadicList(Ts))](0)
  
  @parameter
  for i in range(len(VariadicList(Ts))):
    result[i] = sizeof[Ts[i]]()
    
  return result

fn print_array[T: WritableCollectionElement](arr: InlineArray[T]):
  for i in range(len(arr)):
    print(arr[i])
  

def main():
    print_array(get_sizes())

The expected behaviour is that this would simply print nothing. However, the program does not compile as it fails to run the pass manager. Of course there are more important use cases, which currently can only be covered with a verbous extra overload.

System information

I tested this on Mojo Playground, v24.6
@samufi samufi added bug Something isn't working mojo-repo Tag all issues with this label labels Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

1 participant