Skip to content

Conversation

@gafter
Copy link
Member

@gafter gafter commented Jan 31, 2018

Fix is and pattern-matching behavior in presence of implicit UD conversion
and also an explicit reference conversion between the same types.
User-defined conversions should never be considered for is and pattern-matching.

Customer scenario

See #24522

Bugs this fixes

Fixes #24522

Workarounds, if any

Casting the left-hand-side to object is often a work-around.

Risk

Low, as the fix is quite localized.

Performance impact

Should be slight performance improvement, as we now only check built-in conversions for certain type-check operations.

Is this a regression from a previous update?

Yes. C#6 did not have this bug.

Root cause analysis

We did not realize that it is possible for an implicit user-defined operator to be present when an explicit reference conversion applies.

We now have tests for the ways that symptoms can arise.

How was the bug found?

Customer reported.

Test documentation updated?

N/A

…version

and also an explicit reference conversion. User-defined conversions should
never be considered for `is` and pattern-matching.
Fixes dotnet#24522
@gafter gafter added this to the 15.7 milestone Jan 31, 2018
@gafter gafter self-assigned this Jan 31, 2018
@gafter gafter requested review from a team and agocke January 31, 2018 00:23
@gafter
Copy link
Member Author

gafter commented Feb 1, 2018

@agocke @dotnet/roslyn-compiler may I please have a couple of reviews of this pattern-matching bug fix?

HashSet<DiagnosticInfo> discarded = null;
Conversion c = Compilation.Conversions.ClassifyConversionFromExpression(operand, type, ref discarded);
const bool preferBuiltinConversion = true;
Conversion c = Compilation.Conversions.ClassifyConversionFromExpression(operand, type, ref discarded, preferBuiltinConversion);
Copy link
Contributor

@AlekseyTs AlekseyTs Feb 1, 2018

Choose a reason for hiding this comment

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

preferBuiltinConversion [](start = 114, length = 23)

It doesn't look like passing this value guarantees that user defined conversions are ignored completely. #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

That isn't the intended behavior. It just needs to prioritize builtin conversions over user-defined conversions.

Copy link
Contributor

@AlekseyTs AlekseyTs Feb 1, 2018

Choose a reason for hiding this comment

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

It just needs to prioritize builtin conversions over user-defined conversions.

What would be a valid scenario when a user defined conversion should be accepted here? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know what you mean by "accepted". The conversion is required in the node but isn't used subsequent to lowering. The is operator in the language does not actually require that a conversion exist. The conversion is stored to assist with semantics (specifically warnings) and lowering when the is operator appears in source. Those don't apply to the node produced here.

If it would make it more clear, we can use NoConversion here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or, if you prefer, we can compute a built-in conversion from type.

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Feb 1, 2018

Done with review pass (iteration 1). #Closed

@gafter
Copy link
Member Author

gafter commented Feb 1, 2018

Done with responses to review pass (iteration 1). Do you have any other comments?

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (iteration 2)

@gafter
Copy link
Member Author

gafter commented Feb 1, 2018

@agocke Can you please review this pattern-matching bug fix?

1 similar comment
@gafter
Copy link
Member Author

gafter commented Feb 2, 2018

@agocke Can you please review this pattern-matching bug fix?

@agocke
Copy link
Member

agocke commented Feb 2, 2018

@gafter Looking now.

@gafter gafter merged commit f4402e7 into dotnet:dev15.7.x Feb 6, 2018
heejaechang pushed a commit that referenced this pull request Feb 7, 2018
* Remove duplicate lock DocumentState.s_syntaxTreeToIdMapLock

This lock is only being used to protect access to an instance which contains
internal synchronization.

* Better handle surrounding directives when inlining a local variable.

* Add tests.

* Share code between VB and C#.

* Reduce allocations in UnboundLambda

Fixes #23463

* Restore ReturnInferenceCacheKey as the key for _returnInferenceCache

* Update code to more closely follow patterns of the original code

* Cleanup from code review

* Verify MSBuild version in Developer CMD prompt

Roslyn is designed to have the simplest possible contribution story:
clone then build. Every pre-req needed is either located on the machine
or bootstrapped via NuGet. All the way down to using an xcopy MSBuild if
needed.

The one case which causes a problem is the VS command prompt. In this
case MSBuild is pre-installed on the machine and may or may not be
suitable for building Roslyn.

Previously when building from a VS command prompt we just used whatever
MSBuild was provided. The assumption being a developer command prompt
was an explicit statement of whath MSBuild you wanted to use. Based on
all of our customer reports though this does not seem to be the
assumption that consumers of our repo have. The build gave them no
explicit errors about the provided toolset and hence when the build
failed they assigned flakiness to our repo.

Going forward we are applying the same version validation to MSBuild
when provided via a developer command prompt. If it doesn't match we
will refuse to build asking the user to upgrade VS or build from a
normal command prompt.

* Remove unneeded debugging line

* Comment about pre-release

* Added minimum version

* Add Omit If Default style option

* Add space to be like test without the omit

* Add/Remove without needing a property

* Reformat

* PR feedback

* Fix VB diagnostic based on feedback

* Handle case of NotApplicable modifier and field declaration list

* Fix tests

* PR feedback

* PR feedback

* Support negative null-check when we are suggesting to inline type checks

Fixes #21097
Fixes #24286

* fix a case where persistent storage registration fails and some clean… (#24458)

* fix a case where persistent storage registration fails and some clean up code around it.

* added readonly

* address PR feedback

* removed comments no longer relevant

* renamed lock name

* moved waiter from diagnostics.dll to features.dll where all interfaces are defined. (#24512)

* put listener change back in (#24120)

* leave old types in legacy folder until partner teams move to new interface

* added legacy waiter to support partner teams

* Remove methods indirecting access to _metadataFileNameToConvertedProjectReference

This field is documented as being written and read from any thread,
but in practice all uses are guarded by an AssertIsForeground(). Thus
we can get rid of the helper methods that are trying to "help" by
locking before accessing the fields, making it really hard to track all
the real uses of it.

* Make method static that doesn't need state

* Fix up tests of P2P to metadata reference conversion

It turns out we had some tests, but the tests were disabled. This was
because the tests weren't working properly anyways: they were calling
into UpdateProjectBinPath which only updated some (but not all) of
the project state. That was an internal helper method that shouldn't
be used by tests. Updating the tests to use
SetBinOutputPathAndRelatedData works better.

* Delete debug-only reference validation

This was some legacy code that tried to verify that the references
we have from the project system match up to what DTE and other sources
say. This was debug-only, and the actual asserts were commented out.
This is deadweight at this point, so delete it.

* added and cleaned up logs around build and live diagnostics. (#24551)

also added RoslynActivityLogger that can be enabled through project-system-tool

* Avoid closure allocations on the BindSyntaxTreeToId fast path

* CS1628 error text mentions in parameters; fixes #24584

* Update optimization data to 2.7.0-beta3-62526-01...

* Small cleanup of completion logic.

* Locate implementations for reference assemblies using the process binding path

* Use GlobalAssemblyCache helper to locate assemblies directly in the GAC

* Update InteractiveEditorFeatures to account for a second definition of GlobalAssemblyCache

* Move to xunit.console for CoreClr tests

Previously we were using xunit.console for desktop tests and dotnet-xunit for our
CoreClr tests. This change unifies us on top of xunit.console (now that it has a
netcoreapp2.0 version available).

* Move unix builds to xunit.runner.console as well

* Fixes 559223

Fix and re-enable test that would catch this error

* Update LanguageServices training data again...

* Get actual directory name, not file

* Fix dir name issue

* Cleanup based on code review feedback

* Check fully-qualified names for SuppressIldasmAttribute and ReferenceAssemblyAttribute
* Use correct reference location, or fail decompilation if it's not available

* Fix typo...

* Don't use inferred member name if that creates duplicates (#24632)

* Fixes #23983

* Added test for unique IDEDiagnosticIDs

* Fixed capitalization on local variable

* Fix `is` and pattern-matching behavior in presence of implicit UD conversion (#24547)

* Fix `is` and pattern-matching behavior in presence of implicit UD conversion
and also an explicit reference conversion. User-defined conversions should
never be considered for `is` and pattern-matching.
Fixes #24522
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants