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

Method Type Inference in VB #12932

Merged
merged 2 commits into from
Aug 5, 2016
Merged

Conversation

VSadov
Copy link
Member

@VSadov VSadov commented Aug 4, 2016

The idea is that when (int, long) is passed to (T, U), we can infer T=int, U=long.

The situation is generally more complex though since tuples have Narrowing and Widening conversions as long as underlying types allow that. For example, in the example above, if target is (T, T) the inference will be T=long

The implementation roughly follows the same strategy as in C#. However it is plugged into a substantially different and more complex framework of type inference in VB.

Includes some fixes from the conversions PR feedback.

@VSadov
Copy link
Member Author

VSadov commented Aug 4, 2016

@dotnet/roslyn-compiler - please review

@AdamSpeight2008
Copy link
Contributor

@VSadov Is that a generic tuple? (T,U)

If tupleLiteral.Type IsNot Nothing Then
AddTypeToGraph(argNode, isOutgoingEdge:=True)
Return
End If
Copy link
Member

Choose a reason for hiding this comment

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

I don't think there should be a Return here.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is treated the same as Exit Sub

Copy link
Member

Choose a reason for hiding this comment

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

Right. We should not have an Exit Sub here either. That bypasses the following loop, which is required to get the correct semantics.


In reply to: 73605505 [](ancestors = 73605505)

Copy link
Contributor

Choose a reason for hiding this comment

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

@gafter Thank you, that better clarifies your comment.

Copy link
Contributor

@AdamSpeight2008 AdamSpeight2008 Aug 4, 2016

Choose a reason for hiding this comment

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

Yet it passed the unit tests.

Copy link
Member

Choose a reason for hiding this comment

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

Vlad and I met in my office to discuss the kinds of unit tests needed to demonstrate my point. For example
M((T, U) tuple) with an argument (1, 2). The expressions 1 and 2 will not propagate to give types for T and U because the following loop is skipped. I just placed a brief comment to remind him where in the code we were discussing the issue.


In reply to: 73606403 [](ancestors = 73606403)

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. We should always do the inference from arguments if the target is a tuple type of matching cardinality.
Only if that is not the case we should attempt to infer from the whole tuple literal.

Thanks! Good catch.!


In reply to: 73610026 [](ancestors = 73610026,73606403)

@gafter
Copy link
Member

gafter commented Aug 4, 2016

:shipit:

@VSadov
Copy link
Member Author

VSadov commented Aug 4, 2016

It is a tuple whose elements are typed as generic type parameters.
Tuples themselves, from the language prospective, are not technically generic. They act more like arrays - they are always concrete types, but elements can be typed generically.


In reply to: 237678618 [](ancestors = 237678618)

@jcouv
Copy link
Member

jcouv commented Aug 4, 2016

Starting review

System.ValueTuple`2[System.ValueTuple`2[System.Int32,System.Object],System.ValueTuple`2[System.Int32,System.Object]]

]]>)
End Sub
Copy link
Member

Choose a reason for hiding this comment

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

It's not directly for the PR, but I didn't find a test using tuple syntax but without referencing the ValueTuple library.
In C#, it reports ERR_PredefinedTypeMemberNotFoundInAssembly.

@jcouv
Copy link
Member

jcouv commented Aug 5, 2016

LGTM but I have to say the inference code was a bit over my head with my limited VB knowledge at this point.

@VSadov VSadov merged commit c319d2f into dotnet:features/vbTuples Aug 5, 2016
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.

5 participants