-
Notifications
You must be signed in to change notification settings - Fork 662
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
Wrong "expected" type from the annotation #1192
Comments
I ran into another instance of what is probably the same bug, plus maybe another related bug. In Elm 0.16, the following code: module Buggy where
import Debug
type alias Alias a = a -> a
convert : (a -> b) -> Alias b -> Alias a
convert _ = Debug.crash "unimplemented"
applyToSecond : Alias b -> Alias (a, b)
applyToSecond _ = Debug.crash "unimplemented"
wrongTypeFunction : Int -> String
wrongTypeFunction _ = Debug.crash "unimplemented"
badError : Alias value -> Alias Bool
badError alias =
convert wrongTypeFunction (applyToSecond alias) produces two error messages, both displaying the same type as both expected and actual:
|
@evancz, this looks like a rather serious regression in 0.16. Have you seen it? (I know you have notifications turned off for some repositories.) |
I said "regression" because in 0.15 the reporting here, while using different words, gives correct information where 0.16 doesn't. |
Here's another simpler example of what is probably the same bug. (I originally reported this at elm/error-message-catalog/issues/69, but jvoigtlaender pointed out that wasn't the right place for it.)
This produces the following error message:
|
A lot of people have run across this. Would be great to get a fix out. |
Is the shared characteristic between all these examples that they use a type alias? Can someone link to the definition of |
I guess it's this one: http://package.elm-lang.org/packages/NoRedInk/elm-shrink/1.0.3/Shrink#Shrinker So yes, also a type alias. |
Can we try to figure out cases where this does and does not happen? Like, On Sunday, December 13, 2015, Janis Voigtländer [email protected]
Sent from Gmail Mobile |
Try this, which has wrong behavior: type alias F a = a
f : F a -> a
f = identity vs. the following ones, both of which have the correct behavior: type alias F a = a
f : F Int -> Int
f = identity and type alias F = Int
f : F -> Int
f = identity So the error conditions seem to be the following two coming together:
|
I have an example that might be related which doesn't seem to use a type alias.
This gives an error as-is, but is fixed if you replace (number, number) with comparable. |
@rhofour, this might be a separate error that has to do with Specifically, these two examples might be better suited to get a hang on what goes wrong with your example as well: import Set
f : List number -> Set.Set number
f = Set.fromList vs. import Set
f : List (Int,number) -> Set.Set (Int,number)
f = Set.fromList |
I have opened a separate issue (#1281) related to @rhofour's case. I think that other error might influence what is shown in his case. So for the issue at hand here, I still conjecture that, in response to @evancz's question "when exactly does this bad thing happen", the answer is: "when a type alias definition with a type variable argument is used somewhere in a still polymorphic fashion". |
Has this somehow got worse in 0.17 (or do the new features make it more likely to occur)? I ask because I have never noticed this bug before, but since I started playing with 0.17 I have noticed it multiple times in multiple situations. |
It has come up pretty often before 0.17 already, as you can see above... But, one reason you may see it come up particularly often with 0.17 is that more stuff is |
Cool, I have seen this a couple times with 0.17 during development and wasn't sure what was up. Thank you for the http://sscce.org/ I'll see if I can figure it out. |
Alright, it was a dumb mistake in which I unified variables before I checked all the subparts. This meant that the subparts would still fail, but only after the types were set to be the same. Anyway, here's the new result from the example that didn't need any imports:
|
That's great news, thanks Evan!
|
The issue isn't fixed. The one example above is handled correctly now, but others that occur in comments above are not. Specifically, the SSCCE I gave: type alias F a = a
f : F a -> a
f = identity Should be accepted, but isn't on 0.17 http://elm-lang.org/try. |
New issue with SSCCE. |
EDIT: as jvoigtlaender pointed, the error I post was actually in my own code, sorry for posting that! I think I also hit this bug. I do not truly yet understand the whole type system, but adding a "case" statement for a let definition makes the compiler infer a different type and fail. I try to bring an example of code that may fail or work depending on a let statement. Compiler error:
Code (depending how you define the "is_checked" at lines 16/17 the type inferred is different and the compilation fails or succeeds:
I reduced the amount of code to paste that here but the error is the same.
EDIT: code formatting and elm version |
@vrescobar, yours is a problem in your code, not in the compiler. Specifically, it has nothing to do with the compiler bug this GH issue here is about. The problem in your code comes from having type TodoState = ToDo | Done
type alias TodoItem =
{ message: String
, state: TodoState
} and then item : TodoItem and then trying to do case item.itemState of
ToDo -> False
Done -> True Why should this work? Your |
Ups, you are right, I am sorry. Somehow I messed up after a refactoring and I got blind with the Html a/Html b types. |
Is there a newer issue for this? I keep running into this problem with present-day Elm so it certainly hasn't been fixed. (or it regressed) |
File a new issue with an sscce. |
@mgold I'm new to Elm, so I'm not sure what the problem could be, in order to isolate it. |
@Erudition The process is usually to remove stuff (record fields, functions, files, types, ...) until the issue disappears, then put that back in and remove everything else. (Surely an empty program doesn't have the issue, and your program does. By intermediate value theorem you are guaranteed to find the issue source sooner or later 😃 ) |
The "expected" and "actual" rows are the same when they probably shouldn't be.
I would have expected it to say:
The minimal code:
The relevant dependencies:
The text was updated successfully, but these errors were encountered: