kadena-io / pact

The Pact Smart Contract Language
https://docs.kadena.io/build/pact
BSD 3-Clause "New" or "Revised" License
579 stars 100 forks source link

Typechecker does not recognize typed constants #1299

Open CryptoPascal31 opened 1 year ago

CryptoPascal31 commented 1 year ago

Issue description

Typechecker does not recognize typed constants

Steps to reproduce

(module A G
  (defcap G() true)

  (defschema point
    x:integer
    y:integer
  )

  (defconst MY-POINT:object{point} {'x:5, 'y:2})

  (defun get-point-x:integer ()
    (at "x" MY-POINT))
)

(typecheck 'A)

gives

Unable to resolve type (TySchema {_tySchema = TyObject, _tySchemaType = TyVar {_tyVar = SchemaVar {_tvName = "at1_o"}}, _tySchemaPartial = FullSchema})

However if I modify slightly my code to use a function instead of a constant:

(module A G
  (defcap G() true)

  (defschema point
    x:integer
    y:integer
  )

  (defun my-point:object{point} ()
    {'x:5, 'y:2})

  (defun get-point-x:integer ()
    (at "x" (my-point)))
)

(typecheck 'A)

Everything is OK, the typechecker is happy.

Expected Behavior

Since IMHO my code is 100% valid, I would expect the type-checker to pass.

jmcardon commented 11 months ago

Thanks for the report! We'll take a look