Purescript: Internal error for mutually recursive `foreign import data`

Created on 9 Sep 2020  Â·  4Comments  Â·  Source: purescript/purescript

Description

Mutually recursive foreign import data declarations can cause an internal compiler error on the current master.

To Reproduce

module Main where

foreign import data A :: B
foreign import data B :: A
purescript    >       'RecursiveExternData.purs' should compile and run without error: FAIL (0.07s)
purescript    >         uncaught exception: ErrorCall
purescript    >         An internal error occurred during compilation: toExternsDeclaration: no kind 
in toExternsDeclaration
purescript    >         Please report this at https://github.com/purescript/purescript/issues
purescript    >         CallStack (from HasCallStack):
purescript    >           error, called at src/Language/PureScript/Crash.hs:24:3 in purescript-ast-0.
1.0.0-Gtmwmu4N43KCxo7Qi9BiwQ:Language.PureScript.Crash
purescript    >           internalError, called at src/Language/PureScript/Externs.hs:225:18 in pures
cript-0.13.8-8vNPQdyw1kRA1yYdlrf0He:Language.PureScript.Externs

Expected behavior

I'm not sure whether this should be rejected by the compiler or not, but it should at least not result in an internal compiler error.

Additional context

Came across this while trying to implement the refactoring described in https://github.com/purescript/purescript/pull/3910#issuecomment-680252963 - it seems like ExternDataDeclaration values are not designed to be part of a DataBindingGroup.

PureScript version

master

bug

Most helpful comment

I think that it should be rejected by the binding group toposort.

All 4 comments

If I write this in GHCi

data A :: B
data B :: A

I get this:

    • Type constructor ‘A’ cannot be used here
        (it is defined and used in the same recursive group)
    • In the kind ‘A’

I think that it should be rejected by the binding group toposort.

The existing error is CycleInKindDeclaration.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

garyb picture garyb  Â·  4Comments

LiamGoodacre picture LiamGoodacre  Â·  3Comments

MonoidMusician picture MonoidMusician  Â·  3Comments

jpvillaisaza picture jpvillaisaza  Â·  3Comments

hdgarrood picture hdgarrood  Â·  4Comments