GithubHelp home page GithubHelp logo

Comments (4)

stefanos82 avatar stefanos82 commented on September 14, 2024 1

I took this code of yours

local i1, i2: integer = 1, 2
local p1: *integer = &i1
print(i1, i2, $p1, $(&i2))

and wrote you a tiny example to clear things up for you:

do
  local function typenameof(x: auto): string
    return #[tostring(x.type)]#
  end

  local i1: integer, i2 = 1, 2.0
  local p1: *integer = &i1
  print(typenameof(i1), typenameof(i2))
  print(i1, i2, $p1, $(&i2))
end

I borrowed a runtime function @edubart shared with me in the past to clear things up about variable types and used it here to demonstrate for you the current output: we provide the type for variable i1 and let the compiler figure out the type based on the value we assigned to it.

The output should be this:

int64	float64
1	2.0	1	2.0

As we know from the official documentation, type integer is of C type int64_t and Nelua type int64 is exactly the same; basically integer should be seen as an alias for int64.

from nelua-lang.

leafi avatar leafi commented on September 14, 2024

Depending on your judgment, this may actually be a docs clarification request or even a feature enhancement request, not a bug. Writing these test cases, and another that goes local i1, i2: integer, integer, integer, integer, integer = 1, 2; ... really seems to suggest that the supported behavior is: Write exactly zero or one types, anything else is ignored and may confuse the parser.

Edit: No, I'm still confused. With one type, if and only if the variables aren't explicitly initialized:

local function f(p1: *integer, p2: *integer)
  print($p1, $p2)
end

local a, b: integer
f(&a, &b)
$ nelua mulvFunc.nelua
mulvFunc.nelua:1:1: from: AST node Block
local function f(p1: *integer, p2: *integer)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mulvFunc.nelua:6:2: error: in call of function 'f' at argument 1: no viable type conversion from 'pointer(any)' to 'pointer(int64)'
f(&a, &b)
 ^~~~~~~~

from nelua-lang.

stefanos82 avatar stefanos82 commented on September 14, 2024

From your first comment, the code

local i1, i2: integer, integer = 1, 2
local p1: *integer = &i1
print(i1, i2, $p1, $(&i2))

will work if you write your types properly (I understand you got confused):

local i1: integer, i2: integer = 1, 2
local p1: *integer = &i1
print(i1, i2, $p1, $(&i2))

Remember to declare the type right after the variable followed by a colon.

from nelua-lang.

edubart avatar edubart commented on September 14, 2024

There is no bug here, just a misunderstanding on the syntax for declaring multiple typed variables.

In the first example 3 variables was declared, i1, i2 and integer, the integer shadows the original integer primitive, that is why the next line you have an error.

In Nelua, type notations must be immediately on the right for each variable declaration.

from nelua-lang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.