Visual Basic Language Design Meeting Notes - 2016.05.06 #11370
Labels
Area-Language Design
Design Notes
Feature - Ref Locals and Returns
Ref Locals and Returns
Feature - Tuples
Tuples
Language-VB
Uh oh!
There was an error while loading. Please reload this page.
Agenda
ByRef Returns
Today, functions and properties may only return values. This feature allows them to return references to storage locations. This is legal in the CLR with some constraints.
Proposal is that we focus exclusively on the consumption scenario. The primary use-case for declaring members which return ByRef will be specialized collection classes (such as slice) that will almost certainly be written in C# and by a small number of people. It’s very valuable for VB users to be able to use such collection types but without more compelling use cases the production scenario has too much design baggage. Specifically, how to reconcile VB’s copy-in-copy out semantics for properties passed ByRef with returning properties ByRef.
Further, I propose we add no new syntax or take a reference to a storage location, or create a ByRef local. This would limit the use of such collection types to exactly the scenarios supported today by arrays with exactly the same usage syntax.
Decisions
No.
We never call the setter.
Something like that. The IDE team synthesizes invalid syntax for scenarios like this all the time (e.g. indexed properties in C# Metadata-as-source).
Make it work.
Doesn’t work.
Tuples
Tuples allow multiple values, potentially of different types, to be bundled up and passed around as a unit. This is primarily a platform interop feature so all decisions regarding the mutability of the tuple type, how the names of its members are persisted and read from metadata, how equality is computed, and the names and structure of the underlying tuple types are as decided in the C# LDM.
Decisions
Yes.
No.
One major issue is that the parameter names and return variable names would share a namespace so this would be an error:
Counter-proposal: Auto “With” the return variable so you can use .min and .max in the scope of the function.
Let's table this until we get more user/dogfooding feedback. We'll soon know whether this is essential our not.
They are element-wise convertible. The conversion is a widening conversion if and only if each element conversion is a widening conversion and narrowing if any conversion is narrowing.
Same warnings for name mix-ups, case-insensitive name comparisons (of course).
We might need to update the late-binder to support tuple conversions but not for tuple names. Lot of work and so many plot holes as names are associated with declarations, not values. This will also be a problem in the debugger since tuple names won't be there at runtime in many scenarios.
No.
No, as that would make it too difficult to make a tuple with no names.
Initially type-less, but reclassified as values after target-typing/type-inference. Analogous to array literals.
If you bind 'x' in the 'x:=' it should bind as a reference to the x element of the tuple, not a definition. Likewise binding 'z' should bind as would a named argument which does not refer to any parameter defined on that method. Basically, tuple expression names always refer to elements declared elsewhere, either explicitly or implicitly, but are never considered definitions on their own. This means that z:= in this case is an error since (x As Integer, y As Integer) does not define any element z.
Yes, but they need parenthesis. Resolves some ambiguities, such as the last example, which would be a breaking change.
Probably. Though it will be the first time a statement in VB can begin with anything other than a keyword, an identifier, or a number.
Cute but nope.
The (Type1, Type2) syntax is too compelling. It's much more likely to want to define a tuple with no names than one with inferred or dynamic types.
The text was updated successfully, but these errors were encountered: