Skip to content

Commit

Permalink
Add documentation to var return types being broken
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Hauck committed Jul 30, 2015
1 parent 4cfc5b0 commit 34089af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/features/local-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ TODO:
- `LocalScopeBinder.ReportConflictWithLocal()` (twice)
- `LocalScopeBinder.EnsureSingleDefinition()`, handle case where 'name' exists in both `localsMap` and `localFunctionsMap`. Might be related to `LocalFunctionTests.NameConflictLocalVarLast()`
- Defining a local function with a dynamic parameter doesn't work at runtime.
- Return type of `var` is strange - when normally compiling, it works fine, but intellisense/etc doesn't work.
- Return type of `var` is broken - see LocalFunctionSymbol.cs for an explanation. Fixing it will require a large rewrite of much of return type analysis, as the current system assumes that all return types are known (mostly) without examining the method body.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ public TypeSymbol ReturnTypeIterator
}
}

/*
Note: `var` return types are currently very broken in subtle ways, in particular in the IDE scenario when random things are being bound.
The basic problem is that a LocalFunctionSymbol needs to compute its return type, and to do that it needs access to its BoundBlock.
However, the BoundBlock needs access to the local function's return type. Recursion detection is tricky, because this property (.ReturnType)
doesn't have access to the binder where it is being accessed from (i.e. either from inside the local function, where it should report an error,
or from outside, where it should attempt to infer the return type from the block).
The current (broken) system assumes that Binder_Statements.cs BindLocalFunctionStatement will always be called (and so a block will be provided)
before any (valid) uses of the local function are bound that require knowing the return type. This assumption breaks in the IDE, where
a use of a local function may be bound before BindLocalFunctionStatement is called on the corresponding local function.
*/
internal TypeSymbol ComputeReturnType(BoundBlock body, bool returnNullIfUnknown, bool isIterator)
{
if (_returnType != null)
Expand Down

0 comments on commit 34089af

Please sign in to comment.