FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add a hint on attempts to use non-exported constructors · Issue #3636 · purescript/purescript · GitHub

Add a hint on attempts to use non-exported constructors #3636

Description

Suppose I have a module such as:

module Wibble (Foo) where

data Foo = Bar | Baz

where I have chosen (or forgotten) to export the constructors for Foo.
In some other module, I try to import and use the constructors:

module Main where

import Data.Unit (Unit)
import Effect (Effect)
import Effect.Console (log)

import Wibble (Foo(..))

main :: Effect Unit
main =
  let x = Bar
  in log "hello"

This, as expected, fails. However, the error message is a little strange. It says

Error found:
in module Main
at src/Main.purs:11:11 - 11:14 (line 11, column 11 - line 11, column 14)

  Unknown data constructor Bar

The line reference is to the line containing let x = Bar.

I guess my mental model was that (..) meant all the data constructors associated with that type. Whereas it seems to be that, in the context of an import, (..) means all the constructors that were exported, which is a possibly empty list. And in the context of an export (..) means all the constructors associated with that type.

If I write import Wibble (Foo(..)) and Wibble does not export any constructors for Foo would it be possible to throw an error, or at least a warning?

Or should I just abandon (..) entirely and use named imports and exports for constructors?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL