Skip to content

Add valid location list to orphan instance error#3106

Merged
paf31 merged 4 commits intopurescript:masterfrom
i-am-tom:master
Oct 8, 2017
Merged

Add valid location list to orphan instance error#3106
paf31 merged 4 commits intopurescript:masterfrom
i-am-tom:master

Conversation

@i-am-tom
Copy link
Copy Markdown

@i-am-tom i-am-tom commented Oct 6, 2017

Previously, the orphan instance simply said to consider a newtype. Now, it lists all the places in the project that would be considered valid locations for the instance as well. This hopefully closes #3063, and looks a little something like:

Error found:
in module $PSCI
at  line 1, column 1 - line 1, column 35

  Type class instance showFn for

    Data.Show.Show (a -> b)

  is an orphan instance.
  To avoid this error, declare the instance in one of the following modules if possible:

    Data.Show

  Otherwise, consider adding a newtype wrapper.

Previously, the orphan instance simply said to consider a newtype. Now,
it lists all the places in the project that would be considered valid
locations for the instance as well. This hopefully closes #3063.
Copy link
Copy Markdown
Contributor

@paf31 paf31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job, thanks

Copy link
Copy Markdown
Member

@kritzcreek kritzcreek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@LiamGoodacre
Copy link
Copy Markdown
Member

What does the error message look like for:

instance what :: Fail "what"

@LiamGoodacre
Copy link
Copy Markdown
Member

Not that anyone should be writing that, but my intent is to suppose there is a prim type class for which it might make sense to make instances of.

@i-am-tom
Copy link
Copy Markdown
Author

i-am-tom commented Oct 7, 2017

@LiamGoodacre Ha! So, originally, it would have listed Prim as an option. However, I am now filtering it out. What sort of error would you like to see in this instance?

Firstly, there's a little change to the error output in the case of
there being no place for the instance except Prim. Previously, it just
printed an empty list, which didn't make much sense, gramatically. Now,
however, a different error is displayed to point out that there's no
reasonable home for the instance.

As well as this, the `typeModule` function in `TypeChecker.hs` can now
deal with proxy types. Previously, it couldn't, and the tests were
passing really due to an accident of laziness. Now, the tests pass, and
all is well in the world.
@i-am-tom
Copy link
Copy Markdown
Author

i-am-tom commented Oct 7, 2017

Updates from review

Firstly, there's a little change to the error output in the case of
there being no place for the instance except Prim. Previously, it just
printed an empty list, which didn't make much sense, gramatically. Now,
however, a different error is displayed to point out that there's no
reasonable home for the instance.

As well as this, the typeModule function in TypeChecker.hs can now
deal with proxy types. Previously, it couldn't, and the tests were
passing really due to an accident of laziness. Now, the tests pass, and
all is well in the world.

Thinking about it, you'll only ever see, at most, two things in the list
of possible locations. So, we can intercalate the list with `or` and get
a much friendlier-looking error.
Copy link
Copy Markdown
Member

@LiamGoodacre LiamGoodacre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great.

]
_ -> [ Box.text $ "This instance must be declared in "
<> T.unpack formattedModules
<> ", or be defined for a newtype wrapper."
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about the phrasing here; the use of 'must' makes it sound like these are strictly the only two possible solutions. However, there are potentially many other contextually dependent solutions.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

]
, Box.vcat Box.left $ case modulesToList of
[] -> [ line "There is nowhere this instance can be placed without being an orphan."
, line "A newtype wrapper can be used to avoid this problem."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we'd also probably need a link to what the hell a newtype wrapper is and how to define it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spoke to @paf31, suggested that this level of detail would be better suited to the wiki. We're going to talk a bit more about this later, and I'll probably make another docs PR :)

Previously, the error mentioned that the instance "must" be declared in
one of a set of places, which @goodacre.liam (rightly) noted would imply
that there aren't other, equally valid, solutions. The wording has been
altered to address this.
@i-am-tom
Copy link
Copy Markdown
Author

i-am-tom commented Oct 8, 2017

🎉

@paf31 paf31 merged commit 71fc308 into purescript:master Oct 8, 2017
@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Oct 8, 2017

Thanks!

paf31 pushed a commit that referenced this pull request Nov 8, 2017
* Add valid location list to orphan instance error

Previously, the orphan instance simply said to consider a newtype. Now,
it lists all the places in the project that would be considered valid
locations for the instance as well. This hopefully closes #3063.

* Updates from review

Firstly, there's a little change to the error output in the case of
there being no place for the instance except Prim. Previously, it just
printed an empty list, which didn't make much sense, gramatically. Now,
however, a different error is displayed to point out that there's no
reasonable home for the instance.

As well as this, the `typeModule` function in `TypeChecker.hs` can now
deal with proxy types. Previously, it couldn't, and the tests were
passing really due to an accident of laziness. Now, the tests pass, and
all is well in the world.

* Tidy the orphan instance error further.

Thinking about it, you'll only ever see, at most, two things in the list
of possible locations. So, we can intercalate the list with `or` and get
a much friendlier-looking error.

* Adjust wording on error feedback

Previously, the error mentioned that the instance "must" be declared in
one of a set of places, which @goodacre.liam (rightly) noted would imply
that there aren't other, equally valid, solutions. The wording has been
altered to address this.
jutaro pushed a commit to mgmeier/purescript that referenced this pull request Mar 12, 2018
* Add valid location list to orphan instance error

Previously, the orphan instance simply said to consider a newtype. Now,
it lists all the places in the project that would be considered valid
locations for the instance as well. This hopefully closes purescript#3063.

* Updates from review

Firstly, there's a little change to the error output in the case of
there being no place for the instance except Prim. Previously, it just
printed an empty list, which didn't make much sense, gramatically. Now,
however, a different error is displayed to point out that there's no
reasonable home for the instance.

As well as this, the `typeModule` function in `TypeChecker.hs` can now
deal with proxy types. Previously, it couldn't, and the tests were
passing really due to an accident of laziness. Now, the tests pass, and
all is well in the world.

* Tidy the orphan instance error further.

Thinking about it, you'll only ever see, at most, two things in the list
of possible locations. So, we can intercalate the list with `or` and get
a much friendlier-looking error.

* Adjust wording on error feedback

Previously, the error mentioned that the instance "must" be declared in
one of a set of places, which @goodacre.liam (rightly) noted would imply
that there aren't other, equally valid, solutions. The wording has been
altered to address this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Orphan instance error wording reads like a warning

5 participants