-
Notifications
You must be signed in to change notification settings - Fork 790
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
Remove one "impossible" error #5746
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5316,12 +5316,14 @@ and TcPat warnOnUpper cenv env topValInfo vFlags (tpenv, names, takenNames) ty p | |
for (id, pat) in pairs do | ||
match argNames |> List.tryFindIndex (fun id2 -> id.idText = id2.idText) with | ||
| None -> | ||
let caseName = | ||
match item with | ||
| Item.UnionCase(uci, _) -> uci.Name | ||
| Item.ExnCase tcref -> tcref.DisplayName | ||
| _ -> failwith "impossible" | ||
error(Error(FSComp.SR.tcUnionCaseConstructorDoesNotHaveFieldWithGivenName(caseName, id.idText), id.idRange)) | ||
match item with | ||
| Item.UnionCase(uci, _) -> | ||
error(Error(FSComp.SR.tcUnionCaseConstructorDoesNotHaveFieldWithGivenName(uci.Name, id.idText), id.idRange)) | ||
| Item.ExnCase tcref -> | ||
error(Error(FSComp.SR.tcExceptionConstructorDoesNotHaveFieldWithGivenName(tcref.DisplayName, id.idText), id.idRange)) | ||
| _ -> | ||
error(Error(FSComp.SR.tcConstructorDoesNotHaveFieldWithGivenName(id.idText), id.idRange)) | ||
|
||
| Some idx -> | ||
match box result.[idx] with | ||
| null -> | ||
|
@@ -8644,13 +8646,16 @@ and TcItemThen cenv overallTy env tpenv (item, mItem, rest, afterResolution) del | |
assert (isNull(box fittedArgs.[currentIndex])) | ||
fittedArgs.[currentIndex] <- List.item currentIndex args // grab original argument, not item from the list of named parameters | ||
currentIndex <- currentIndex + 1 | ||
else | ||
let caseName = | ||
match item with | ||
| Item.UnionCase(uci, _) -> uci.Name | ||
| Item.ExnCase tcref -> tcref.DisplayName | ||
| _ -> failwith "impossible" | ||
error(Error(FSComp.SR.tcUnionCaseConstructorDoesNotHaveFieldWithGivenName(caseName, id.idText), id.idRange)) | ||
else | ||
match item with | ||
| Item.UnionCase(uci, _) -> | ||
error(Error(FSComp.SR.tcUnionCaseConstructorDoesNotHaveFieldWithGivenName(uci.Name, id.idText), id.idRange)) | ||
| Item.ExnCase tcref -> | ||
error(Error(FSComp.SR.tcExceptionConstructorDoesNotHaveFieldWithGivenName(tcref.DisplayName, id.idText), id.idRange)) | ||
| Item.ActivePatternResult(_,_,_,_) -> | ||
error(Error(FSComp.SR.tcActivePatternsDoNotHaveFields(), id.idRange)) | ||
| _ -> | ||
error(Error(FSComp.SR.tcConstructorDoesNotHaveFieldWithGivenName(id.idText), id.idRange)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we still report that this error message might need to be refined (in case it happens)? Would this be an advantage of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. failwith "impossible" is arguably the worst you can do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes ideally the code would be written in a way to not compile when written incorrectly, but if that cannot be achieved imho throwing is better than doing/reporting potentially incorrect messages There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I think even having a confusing error message is better than what existed. The current state of the world (without @forki's changes) paints the whole editor red if you use the incorrect code: These internal errors are critical to root out given this, since it's pretty much undiagnosable where the user error is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok but imho we still should make sure the error message indicates this is not implemented and something which needs to be fixed if it occurs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't give a wrong message. We just give a very generic one |
||
|
||
assert (Seq.forall (box >> ((<>) null) ) fittedArgs) | ||
List.ofArray fittedArgs | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this case is impossible, correct? Shouldn't we report this somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"impossible"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I mean is that
item
is matched some lines above to be one of the two cases anditem
is immutable? This case means someone has changed something and missed to do some work. Removingfailwith
means the mistake will be spotted later (or not at all)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually that is what already happend. the case was added and nobody changed the failwith "impossible"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But line above reads
| (Item.UnionCase _ | Item.ExnCase _) as item ->
how can this match another case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it does not today. wait until someone adds the active pattern part ;-)