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

Indexing array of thing gives (thing?) ? #105

Open
Zash opened this issue Nov 16, 2016 · 1 comment
Open

Indexing array of thing gives (thing?) ? #105

Zash opened this issue Nov 16, 2016 · 1 comment

Comments

@Zash
Copy link

Zash commented Nov 16, 2016

This is things.tl:

local interface thing
	x:string
end

local things:{thing} = {};

for i = 1, #things do
	local t:thing = things[i];
	print(t.x);
end

This is the output of tlc things.tl:

things.tl:10:8: type error, attempt to assign 'thing?' to 'thing'
local t:thing = things[i];
      ^
things.tl:11:8: type error, attempt to index 'thing?' with '"x"'
print(t.x);
      ^

Why is this? How do I tell it that I'm really sure that it's not out of bounds?

@Veltas
Copy link
Contributor

Veltas commented Nov 16, 2016

I recommend aliasing assert like suggested here: #89 (comment)

From that issue you'll see that there is a better way of doing this planned, but for now this is what we have.

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