-
Notifications
You must be signed in to change notification settings - Fork 822
Give better error message when IF Statement has context requirements #3150
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
Conversation
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.
Looks good - could do with a test case?
src/fsharp/FSComp.txt
Outdated
@@ -17,6 +17,7 @@ undefinedNameTypeParameter,"The type parameter %s is not defined." | |||
undefinedNamePatternDiscriminator,"The pattern discriminator '%s' is not defined." | |||
replaceWithSuggestion,"Replace with '%s'" | |||
missingElseBranch,"The 'if' expression is missing an 'else' branch. The 'then' branch has type '%s'. Because 'if' is an expression, and not a statement, add an 'else' branch which returns a value of the same type." | |||
ifExpression,"The 'if' expression needs to return type '%s' in order to satisfy context type requirements. It currently returns type '%s'." |
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.
'Returns' may be a bit of a misnomer here - the expression itself has a type. Maybe just: "The 'if' expressions needs to have type '%s' in order to satisfy context type requirements. It currently has type '%s'."
Also out of interest what is a 'context type requirement'?
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.
mmm if you have to ask then it's probably not good.
I wanted to tell that the type requirement comes from the context of the expression - not from the expression itself.
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.
@saul @isaacabraham how could we express this better?
Agent went offline during the build - sigh |
src/fsharp/FSComp.txt
Outdated
@@ -17,6 +17,7 @@ undefinedNameTypeParameter,"The type parameter %s is not defined." | |||
undefinedNamePatternDiscriminator,"The pattern discriminator '%s' is not defined." | |||
replaceWithSuggestion,"Replace with '%s'" | |||
missingElseBranch,"The 'if' expression is missing an 'else' branch. The 'then' branch has type '%s'. Because 'if' is an expression, and not a statement, add an 'else' branch which returns a value of the same type." | |||
ifExpression,"The 'if' expression needs to return type '%s' in order to satisfy context type requirements. It currently has type '%s'." |
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.
"needs to return type" -> "must be of type"
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.
you can lose the 'in order' as well.
@@ -17,6 +17,7 @@ undefinedNameTypeParameter,"The type parameter %s is not defined." | |||
undefinedNamePatternDiscriminator,"The pattern discriminator '%s' is not defined." | |||
replaceWithSuggestion,"Replace with '%s'" | |||
missingElseBranch,"The 'if' expression is missing an 'else' branch. The 'then' branch has type '%s'. Because 'if' is an expression, and not a statement, add an 'else' branch which returns a value of the same type." |
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.
"returns a value of the same type" -> "has a value of the same type"
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.
fixed with the other PR
src/fsharp/FSComp.txt
Outdated
@@ -17,6 +17,7 @@ undefinedNameTypeParameter,"The type parameter %s is not defined." | |||
undefinedNamePatternDiscriminator,"The pattern discriminator '%s' is not defined." | |||
replaceWithSuggestion,"Replace with '%s'" | |||
missingElseBranch,"The 'if' expression is missing an 'else' branch. The 'then' branch has type '%s'. Because 'if' is an expression, and not a statement, add an 'else' branch which returns a value of the same type." | |||
ifExpression,"The 'if' expression needs to return type '%s' in order to satisfy context type requirements. It currently has type '%s'." | |||
elseBranchHasWrongType,"All branches of an 'if' expression must return the same type. This expression was expected to have type '%s' but here has type '%s'." |
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.
"must return the same type" -> "must be of the same type"
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.
Approved with a minor tweak to the message text.
src/fsharp/FSComp.txt
Outdated
@@ -17,6 +17,7 @@ undefinedNameTypeParameter,"The type parameter %s is not defined." | |||
undefinedNamePatternDiscriminator,"The pattern discriminator '%s' is not defined." | |||
replaceWithSuggestion,"Replace with '%s'" | |||
missingElseBranch,"The 'if' expression is missing an 'else' branch. The 'then' branch has type '%s'. Because 'if' is an expression, and not a statement, add an 'else' branch which returns a value of the same type." | |||
ifExpression,"The 'if' expression needs to return type '%s' in order to satisfy context type requirements. It currently has type '%s'." |
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.
you can lose the 'in order' as well.
fixed wording |
@forki thanks for this. Kevin |
fixes #3146