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

The JS backend does not reduce constructor type signatures #5602

Closed
nad opened this issue Oct 18, 2021 · 0 comments
Closed

The JS backend does not reduce constructor type signatures #5602

nad opened this issue Oct 18, 2021 · 0 comments
Assignees
Labels
backend: js JavaScript generation backend type: bug Issues and pull requests about actual bugs
Milestone

Comments

@nad
Copy link
Contributor

nad commented Oct 18, 2021

The following code is not compiled correctly by the JS backend:

open import Agda.Builtin.IO
open import Agda.Builtin.String
open import Agda.Builtin.Unit

postulate
  putStr : String  IO ⊤

{-# COMPILE JS putStr =
    function (x) {
      return function(cb) {
        process.stdout.write(x); cb(0); }; } #-}

F : Set  Set
F A = A  A

data D : Set where
  c₀ : D
  c₁ : F D

f : D  String
f c₀     = "OK\n"
f (c₁ x) = f x

main = putStr (f (c₁ c₀))
$ NODE_PATH=. nodejs jAgda.Bug.js
[…]/jAgda.Bug.js:10
exports["D"]["c₁"] = a => a["c₁"]();
                                 ^

TypeError: a.c₁ is not a function
    at Object.exports.D.c₁.a [as c₁] ([…]/jAgda.Bug.js:10:34)
    at Object.<anonymous> ([…]/jAgda.Bug.js:18:25)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

The code is compiled successfully if F D is replaced by D → D.

I constructed the test case above after seeing the following code:

Constructor{conData = p, conPars = nc} -> do
let np = arity t - nc

Note the documentation of arity:

-- | Doesn't do any reduction.
arity :: Type -> Nat

@nad nad added type: bug Issues and pull requests about actual bugs backend: js JavaScript generation backend labels Oct 18, 2021
@nad nad added this to the 2.6.3 milestone Oct 18, 2021
@nad nad self-assigned this Oct 18, 2021
nad added a commit that referenced this issue Oct 18, 2021
@nad nad closed this as completed in 152efd6 Oct 18, 2021
@andreasabel andreasabel modified the milestones: 2.6.3, 2.6.2.1 Nov 17, 2021
andreasabel pushed a commit that referenced this issue Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: js JavaScript generation backend type: bug Issues and pull requests about actual bugs
Projects
None yet
Development

No branches or pull requests

2 participants