more meaningful error for empty contract state #289

Closed
opened 2020-11-22 02:27:05 +09:00 by zxq9 · 4 comments
zxq9 commented 2020-11-22 02:27:05 +09:00 (Migrated from gitlab.com)

Created by: nikita-fuchs

Currently for

contract Test =
  record state = {} // define map for balances
  stateful entrypoint init() : state = {} // give the deployer some tokens

I'm getting

type_error: Cannot unify map('a, 'b) and state
At: Line 0, column 0

Not sure about the sense behind this exactly, but as this is not an unlikely constellation, could we tell people something more meaningful in return ?

*Created by: nikita-fuchs* Currently for ``` contract Test = record state = {} // define map for balances stateful entrypoint init() : state = {} // give the deployer some tokens ``` I'm getting ``` type_error: Cannot unify map('a, 'b) and state At: Line 0, column 0 ``` Not sure about the sense behind this exactly, but as this is not an unlikely constellation, could we tell people something more meaningful in return ?
zxq9 commented 2021-05-26 20:13:33 +09:00 (Migrated from gitlab.com)

Created by: thepiwo

In record state = {} you have to define your type of state instead of the actual value of empty map

*Created by: thepiwo* In `record state = {}` you have to define your type of state instead of the actual value of empty map
ghallak commented 2022-03-01 00:18:17 +09:00 (Migrated from gitlab.com)

@nikita-fuchs At first look I would not expect your code to show any error, I think {} should either construct an empty record or an empty map, depending on the type, but I'm not sure if this was done on purpose, or if it's a bug.

Do you think that your code should pass? Or just fail with a clearer error message?

Btw, this error happens not only for empty contract state, but for all empty record constructions.

@nikita-fuchs At first look I would not expect your code to show any error, I think `{}` should either construct an empty record or an empty map, depending on the type, but I'm not sure if this was done on purpose, or if it's a bug. Do you think that your code should pass? Or just fail with a clearer error message? Btw, this error happens not only for empty contract state, but for all empty record constructions.
ghallak commented 2022-05-21 23:01:39 +09:00 (Migrated from gitlab.com)

@UlfNorell Could you tell why {} is used for empty map construction (and not for empty record construction)? Should it also be used for empty record construction? And if not, how is it possible to construct an empty record?

@UlfNorell Could you tell why `{}` is used for [empty map construction](https://github.com/aeternity/aesophia/blob/a894876f56a818f6237259a7c48cbe6f4a4c01f8/src/aeso_parser.erl#L399) (and not for empty record construction)? Should it also be used for empty record construction? And if not, how is it possible to construct an empty record?
zxq9 commented 2022-05-23 17:10:26 +09:00 (Migrated from gitlab.com)

Created by: UlfNorell

I don't think there are any deep reasons for why it's not also allowed for an empty record. Empty maps are important to be able to construct, whereas the empty record type is mostly a curiosity, so I think we didn't want to spend the effort on making the type checker handle the overloading.

*Created by: UlfNorell* I don't think there are any deep reasons for why it's not also allowed for an empty record. Empty maps are important to be able to construct, whereas the empty record type is mostly a curiosity, so I think we didn't want to spend the effort on making the type checker handle the overloading.
Sign in to join this conversation.
No Milestone
No project
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: QPQ-AG/sophia#289
No description provided.