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

Declaring global or local record types generates variable assignment #632

Closed
ethernidee opened this issue Feb 17, 2023 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@ethernidee
Copy link

Could you explain this strange behavior?

global type Boss1 = record
  name: string
  age:  integer
end

global record Boss2
  name: string
  age:  integer
end

local record Boss3
  name: string
  age:  integer
end

Generates 3 assignments:

Boss1 = {}
Boss2 = {}
local Boss3 = {}

Another example from tutorial:

local record Color
   red: integer
   green: integer
   blue: integer
end

Generates Color = {}

But if we add declare another variable

local record Color
   red: integer
   green: integer
   blue: integer
end

local teal_color <total>: Color = {
   red = 0,
   green = 128,
   blue = 128,
}

The assignment is gone!

local teal_color = {
   red = 0,
   green = 128,
   blue = 128,
}

Why type (structure shape) declaration generates variable assignment? Why this assignment sometimes disappear?

@hishamhm hishamhm added the bug Something isn't working label Feb 27, 2023
@hishamhm
Copy link
Member

At first glance, this sounds like a bug — in the current version, the assignment should only be generated when needed.

@ethernidee
Copy link
Author

Thanks for reply. All examples can be tested on official Teal playground.

@hishamhm
Copy link
Member

This is now fixed in master: unused global types still generate the empty table, as those declarations may be used as a table from other modules, but unused local types now don't generate any code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants