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

Improve error reporting: Missing = on type declaration #9642

Merged
merged 5 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/fsharp/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,7 @@ notAFunctionButMaybeDeclaration,"This value is not a function and cannot be appl
3351,chkFeatureNotRuntimeSupported,"Feature '%s' is not supported by target runtime."
3352,typrelInterfaceMemberNoMostSpecificImplementation,"Interface member '%s' does not have a most specific implementation."
3353,chkFeatureNotSupportedInLibrary,"Feature '%s' requires the F# library for language version %s or greater."
3360,parsEqualsMissingInTypeDefinition,"Unexpected token in type definition. Expected '=' after the type '%s'."
useSdkRefs,"Use reference assemblies for .NET framework references when available (Enabled by default)."
optsLangVersion,"Display the allowed values for language version, specify language version such as 'latest' or 'preview'"
optsSupportedLangVersions,"Supported language versions:"
Expand Down
14 changes: 12 additions & 2 deletions src/fsharp/pars.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -1496,8 +1496,14 @@ tyconDefn:
| typeNameInfo
{ TypeDefn($1, SynTypeDefnRepr.Simple(SynTypeDefnSimpleRepr.None($1.Range), $1.Range), [], $1.Range) }

| typeNameInfo EQUALS tyconDefnRhsBlock
{ let nameRange = rhs parseState 1
| typeNameInfo opt_equals tyconDefnRhsBlock
{ if not $2 then (
let (ComponentInfo(_, _, _, lid, _, _, _, _)) = $1
// While the spec doesn't allow long idents here, the parser doesn't enforce this, so take one ident
let typeNameId = List.last lid
raiseParseErrorAt (rhs parseState 2) (FSComp.SR.parsEqualsMissingInTypeDefinition(typeNameId.ToString()))
)
let nameRange = rhs parseState 1
let (tcDefRepr:SynTypeDefnRepr), members = $3 nameRange
let declRange = unionRanges (rhs parseState 1) tcDefRepr.Range
let mWhole = (declRange, members) ||> unionRangeWithListBy (fun (mem:SynMemberDefn) -> mem.Range)
Expand Down Expand Up @@ -5445,6 +5451,10 @@ deprecated_opt_equals:
| EQUALS { deprecatedWithError (FSComp.SR.parsNoEqualShouldFollowNamespace()) (lhs parseState); () }
| /* EMPTY */ { }

opt_equals:
| EQUALS { true }
| /* EMPTY */ { false }

opt_OBLOCKSEP:
| OBLOCKSEP { }
| /* EMPTY */ { }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.ComponentTests.ErrorMessages

open Xunit
open FSharp.Test.Utilities
open FSharp.Compiler.SourceCodeServices


module ``Type definition missing equals`` =

[<Fact>]
let ``Missing equals in DU``() =
CompilerAssert.TypeCheckSingleError
"""
type X | A | B
"""
FSharpErrorSeverity.Error
3360
(2, 8, 2, 9)
"Unexpected token in type definition. Expected '=' after the type 'X'."
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<Compile Include="EmittedIL\Operators.fs" />
<Compile Include="EmittedIL\Literals.fs" />
<Compile Include="EmittedIL\TailCalls.fs" />
<Compile Include="ErrorMessages\TypeEqualsMissingTests.fs" />
<Compile Include="ErrorMessages\AccessOfTypeAbbreviationTests.fs" />
<Compile Include="ErrorMessages\AssignmentErrorTests.fs" />
<Compile Include="ErrorMessages\ClassesTests.fs" />
Expand Down