question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Array types in function arguments

See original GitHub issue

Overview

Array types should be acceptable function arguments. Currently, we do not have parser support for them.

Expected

A function can be declared with an array type as argument.

Actual

SyntaxError: 
function testa(arr: i32[]): void {
                       ^ Unexpected token Punctuator
Expected: "Identifier"
  at testa (unknown.walt:7:23)
walt.js:3238:12

Acceptance Criteria

  • Tests for the above case
  • Tests pass

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
ballercatcommented, Dec 26, 2017

Isn’t it a goal to support most of the Flow syntax?

I want to clear something up. The goal is to use flow to accomplish a specific goal of using JavaScript syntax to write WebAssembly. Supporting most of flow would mean supporting most of JavaScript, which is unlikely.

The Array<i32> syntax does make sense if you expect flowtype to be re-implemented here. But re-implementing flow is not really a goal, simply a means to an end. I also wonder if there is a better argument made for the additional syntax other than I prefer it over the other because to me it’s not clear why either superior to the other.

Having an i32[] syntax is good because it’s simple to implement and simple to understand and it’s rather stable at this point. I’d like to see this project move past the alpha stage and have some real-world examples out there before exploring additional syntax. Like @Baransu said having an Array<> style syntax implies that there might be some generics-like stuff around, which there isn’t.

1reaction
baransucommented, Dec 26, 2017

Maybe we can add flow as a part of the compiler? As you said reimplementing it isn’t the goal but maybe we can leverage work that already been done. If we want to follow JavaScript and Flow syntax we can add flow as the first step of the validation. After that we will have the quarantee that we have correct typing so compiler can focus on more important things.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing Arrays as Function Arguments in C - Tutorialspoint
If you want to pass a single-dimension array as an argument in a function, you would have to declare a formal parameter in...
Read more >
Passing Arrays as Function Arguments | SamanthaMing.com
If you want to pass an array into a variadic function. You can use ES6 spread to turn that array into a list...
Read more >
7.7. Arrays And Functions
Arrays are always passed to functions (i.e., passed as function arguments) by pointer. With these concepts understood and reviewed as needed, we are...
Read more >
Passing Array to a Function in C++ Programming - Programiz
In this tutorial, we will learn how to pass a single-dimensional and multidimensional array as a function parameter in C++ with the help...
Read more >
The arguments object - JavaScript - MDN Web Docs - Mozilla
arguments is an Array-like object accessible inside functions that contains the values of the arguments passed to that function.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found