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

The (default) type of an array literal and CArray vs Array distinction #40

Open
jstasiak opened this issue Nov 3, 2018 · 1 comment

Comments

@jstasiak
Copy link
Contributor

jstasiak commented Nov 3, 2018

  • Kit version: ad8de26
  • OS/Platform: not relevant

I wanted to pass an Array to a function and tried to use an array literal:

function fun(a: Array[Int]) {
}

function main() {
    fun([1, 2, 3]);
}

It doesn't work right now:

% kitc test.kit
[2018-11-03 18:01:51.303552] ===> parsing and building module graph
[2018-11-03 18:01:51.322517] ===> processing C includes
[2018-11-03 18:01:51.535590] ===> resolving module types
[2018-11-03 18:01:51.556841] ===> typing module content
----------------------------------------
Error: ./test.kit:5: Function arg types must match the function's declaration:

  @./test.kit:5:9-17
       5        fun([1, 2, 3]);
                    ^^^^^^^^^

    Expected type:  kit.array.Array[Int]
      Actual type:  kit.common.CArray[Int8, $3]

[2018-11-03 18:01:51.601764] ===> total time: 0.297389s
[2018-11-03 18:01:51.602297] ERR: compilation failed (1 errors)

Doing an explicit cast doesn't work either:

% kitc test.kit
[2018-11-03 18:02:44.750964] ===> parsing and building module graph
[2018-11-03 18:02:44.772141] ===> processing C includes
[2018-11-03 18:02:45.005430] ===> resolving module types
[2018-11-03 18:02:45.026562] ===> typing module content
----------------------------------------
Error: ./test.kit:5: Invalid cast: kit.common.CArray[Int8, $3] as kit.array.Array[Int]

  @./test.kit:5:9-31
       5        fun([1, 2, 3] as Array[Int]);
                    ^^^^^^^^^^^^^^^^^^^^^^^

[2018-11-03 18:02:45.068829] ===> total time: 0.317073s
[2018-11-03 18:02:45.069523] ERR: compilation failed (1 errors)

I've been wondering - maybe it should be possible?

@bendmorris
Copy link
Member

Known limitation right now. Currently array literals are typed as CArrays. I'm planning on handling this using rewrite rules in the future - a type will be able to define a rule that turns a literal into an instance of that type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants