Comments (4)
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.
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.
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.
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)
- (@span(byte)){...} ordered field cast permits invalid, rejects valid construction HOT 1
- Executables reflect compile-time isatty conditions HOT 3
- <comptime> record parameters can't be provided; fields can't be used in runtime code HOT 1
- Copyright timespan needs update HOT 3
- Invalid unitname generated for directories that look like numeric literals HOT 1
- No line number in error if a hashmap index has a type error
- Range check error messages point to library code (point of check) rather than user code (point of error) HOT 1
- Function variables can collide with C identifiers HOT 1
- Confusing errors with varargs
- Permit function returns in generic instantiation, not just types
- Broken preprocessor after 9faaa66e HOT 3
- Comparison of a pointer with nil generates unexpected C code HOT 2
- we need nelua debugger(vscode) or tell us how to debug my app? HOT 2
- Compatible with Lua C plug-in HOT 2
- LFS: can't change directory with `lfs.chdir` HOT 1
- error while compiling when a source file starts with a number HOT 1
- Compiler hangs when cgenerator.lua errors
- Can't compile fibonacci example
- Can't compile fibonacci example
- Support actual closures via struct
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nelua-lang.