question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Probably a bug with CS8302

See original GitHub issue

Steps to Reproduce:

Use #error version:7.1 with LangVersion set to 7.1

Expected Behavior:

No diagnostic

Actual Behavior:

error CS8302: Feature 'version' is not available in C# 7.1. Please use language version 7.1 or greater.

The error message looks very strange.

The problem lies in DirectiveParser.cs, more specifically, this part of code:

if (this.Options.LanguageVersion != LanguageVersion.Preview &&
    errorText.StartsWith(versionMarker, StringComparison.Ordinal) &&
    LanguageVersionFacts.TryParse(errorText.Substring(versionMarker.Length), out var languageVersion))
{
    ErrorCode error = this.Options.LanguageVersion.GetErrorCode();
    eod = this.AddError(eod, triviaOffset, triviaWidth, error, "version", new CSharpRequiredLanguageVersion(languageVersion));
}

I think the if condition needs to compare the parsed languageVersion with this.Options.LanguageVersion or this.Options.SpecifiedLanguageVersion (not sure what’s the difference between them, hope someone can clear this up for me).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jcouvcommented, Aug 24, 2020

Since #error version:<version> is not meant for users, I don’t worry about the quality of the diagnostic message. I’ll go ahead and close this issue as by-design. Thanks

1reaction
RikkiGibsoncommented, Aug 24, 2020

Whoops, I recently added a PR in dotnet/docs adding information about #error version. Should I revert it?

I think it’s fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature 'using declarations' is not available in C# 7.3. ...
When using Visual Studio Enterprise 16.3.7 on two separate machines, one builds fine and the other machine throws the error: Feature 'using ...
Read more >
World's First Computer Bug
On September 9, 1947, a team of computer scientists reported the world's first computer bug—a moth trapped in their computer at Harvard ...
Read more >
Software bug
A software bug is an error, flaw or fault in the design, development, or operation of computer software that causes it to produce...
Read more >
Moth in the machine: Debugging the origins of 'bug'
Did Grace Hopper really invent the term 'bug' to describe software errors? Nope. Here's the real story.
Read more >
Your favorite candy probably has bugs in it, and that's ...
Your favorite candy probably has bugs in it, and that's really okay - The Washington Post.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found