Skip to content
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

Update pattern matching error message. #5007

Merged
merged 4 commits into from May 26, 2018

Conversation

isaacabraham
Copy link
Contributor

This is a small change that (IMO) improves the error message displayed when different branches of a pattern match return values of different types.

Before

All branches of a pattern match expression must have the same type. This expression was expected to have type 'string', but here has type 'int'.

After

All branches of a pattern match expression must return values of the same type. The first branch returned a value of type 'string', but this branch returned a value of type 'int'."

@vasily-kirichenko
Copy link
Contributor

Excellent, the message has always been tricky to understand.

Copy link
Contributor

@cartermp cartermp left a comment

Choose a reason for hiding this comment

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

I like this change a lot.

Copy link
Contributor

@forki forki left a comment

Choose a reason for hiding this comment

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

We have no tests?

@KevinRansom
Copy link
Member

@isaacabraham I'll take care of the errors.

@@ -178,7 +178,7 @@ type internal SR private() =
/// All branches of an 'if' expression must have the same type. This expression was expected to have type '%s', but here has type '%s'.
/// (Originally from ../FSComp.txt:24)
static member elseBranchHasWrongType(a0 : System.String, a1 : System.String) = (GetStringFunc("elseBranchHasWrongType",",,,%s,,,%s,,,") a0 a1)
/// All branches of a pattern match expression must have the same type. This expression was expected to have type '%s', but here has type '%s'.
/// All branches of a pattern match expression must return values of the same type. The first branch returned a value of type '%s', but this branch returned a value of type '%s'.
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't it still be return expressions and returned an expression ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmmm. I'm not sure :-)

@isaacabraham
Copy link
Contributor Author

@KevinRansom I'm not sure what the error is anyway - can you explain for future reference? Thanks!

@KevinRansom
Copy link
Member

The error is:

  D:\j\w\release_ci_pa---3f142ccc\packages\XliffTasks.0.2.0-beta-000081\build\XliffTasks.targets(90,5): error : '..\xlf\FSComp.txt.en.xlf' is out-of-date with 'obj\release\net40\FSComp.resx'. 
Run `msbuild /t:UpdateXlf` to update .xlf files or set UpdateXlfOnBuild=true to update them on every build, but note that it is strongly discouraged to set UpdateXlfOnBuild=true 
in official/CI build environments as they should not modify source code during the build. [D:\j\w\release_ci_pa---3f142ccc\src\fsharp\FSharp.Compiler.Private\FSharp.Compiler.Private.fsproj]

The fix is to run :

msbuild D:\j\w\release_ci_pa---3f142ccc\src\fsharp\FSharp.Compiler.Private\FSharp.Compiler.Private.fsproj /t:UpdateXlf
then add and commit the updtaed .xlf files.

@KevinRansom
Copy link
Member

@isaacabraham
and actual test errors.

The expected text needs updating

Errors and Failures

1) Error : FSharp-Tests-Core+TypecheckTests.type check neg20
System.Exception : neg20.err neg20.bsl differ; "diff between [D:\j\w\release_ci_pa---866fd2c3\tests\fsharp\typecheck\sigs\neg20.bsl] and [D:\j\w\release_ci_pa---866fd2c3\tests\fsharp\typecheck\sigs\neg20.err]
line 115
 - neg20.fs(87,54,87,61): typecheck error FS0001: All branches of a pattern match expression must have the same type. This expression was expected to have type 'B', but here has type 'C'.
 + neg20.fs(87,54,87,61): typecheck error FS0001: All branches of a pattern match expression must return values of the same type. The first branch returned a value of type 'B', but this branch returned a value of type 'C'.
"; neg20.vserr neg20.bsl differ; "diff between [D:\j\w\release_ci_pa---866fd2c3\tests\fsharp\typecheck\sigs\neg20.bsl] and [D:\j\w\release_ci_pa---866fd2c3\tests\fsharp\typecheck\sigs\neg20.vserr]
line 115
 - neg20.fs(87,54,87,61): typecheck error FS0001: All branches of a pattern match expression must have the same type. This expression was expected to have type 'B', but here has type 'C'.
 + neg20.fs(87,54,87,61): typecheck error FS0001: All branches of a pattern match expression must return values of the same type. The first branch returned a value of type 'B', but this branch returned a value of type 'C'.
"
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1645.Invoke(String message) in D:\j\w\release_ci_pa---866fd2c3\src\fsharp\FSharp.Core\printf.fs:line 1645

2) Error : FSharp-Tests-Core+TypecheckTests.type check neg80
System.Exception : neg80.vserr neg80.vsbsl differ; "diff between [D:\j\w\release_ci_pa---866fd2c3\tests\fsharp\typecheck\sigs\neg80.vsbsl] and [D:\j\w\release_ci_pa---866fd2c3\tests\fsharp\typecheck\sigs\neg80.vserr]
line 6
 - neg80.fsx(79,6,79,6): typecheck error FS0001: All branches of a pattern match expression must have the same type. This expression was expected to have type 'string', but here has type 'unit'.
 + neg80.fsx(79,6,79,6): typecheck error FS0001: All branches of a pattern match expression must return values of the same type. The first branch returned a value of type 'string', but this branch returned a value of type 'unit'.
"
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1645.Invoke(String message) in D:\j\w\release_ci_pa---866fd2c3\src\fsharp\FSharp.Core\printf.fs:line 1645
   at SingleTest.singleNegTest(TestConfig cfg, String testname) in D:\j\w\release_ci_pa---866fd2c3\tests\fsharp\single-test.fs:line 235

R

@KevinRansom
Copy link
Member

@dotnet-bot test Ubuntu16.04 Release_default Build please

@KevinRansom
Copy link
Member

@isaacabraham

Thank you.

@KevinRansom KevinRansom merged commit 8316a79 into dotnet:master May 26, 2018
@isaacabraham
Copy link
Contributor Author

Thank you for fixing the tests. Next time I'll check that stuff myself, now that I know what's needed!

@isaacabraham isaacabraham deleted the improve-pm-error branch May 26, 2018 14:12
@KevinRansom
Copy link
Member

Thank for the PR.

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.

None yet

6 participants