Skip to content

Commit e1a3e8a

Browse files
committed
resolver fixes (#1695)
* added AsTypeName to the context-sensitive commandbar * clear built-in references at every resolution; fixed issue with null parse trees, given built-in modules get a module state instance. * fixed OverflowException in GetTypeName; built-in parameters now have return type info :) * returning built-in members now have return type info as well * removed hard-coded defaults in ClassModuleDeclaration * added IsBadReadPtr check in COM declarations collector * Implemented CanExecute in Project Explorer rename command * cleaned up FormDesignerRefactorRename command * fixed IOExceptions in QualifiedModuleName * use filename, not buildfilename * GetDisplayName being the part in parens, should be null when not applicable; made it private * renamed namespace Rubberduck.UI.CodeInspections to Rubberduck.UI.Inspections for consistency with Rubberduck.Inspections namespace * changed background color of bottom panel in CodeExplorer and InspectionResults toolwindows * fixed broken keybinding "Esc" -> "Escape" * added copy/export button to SearchView (todo: implement ExecuteCopyResultsCommand) * Revert "added copy/export button to SearchView (todo: implement ExecuteCopyResultsCommand)" This reverts commit e9946b7. * assert ProjectId isn't null * fixes #1664 * some French translations * fixed possible NRE's in QualifiedModuleName * fixes #1671 * changed wording of fr resources for settings dialog (left pane items) * fixes #1672 * more French translations * fix RuntimeBinderException with optional object parameters (resolver bug) * fixed AsTypeName of optional parameters with a default value * fixed "resolving" state in the status bar
1 parent 4866288 commit e1a3e8a

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

Rubberduck.Parsing/Binding/BindingService.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Antlr4.Runtime;
1+
using System.Diagnostics;
2+
using Antlr4.Runtime;
3+
using Rubberduck.Parsing.Grammar;
24
using Rubberduck.Parsing.Symbols;
35

46
namespace Rubberduck.Parsing.Binding
@@ -39,7 +41,13 @@ public IBoundExpression ResolveDefault(Declaration module, Declaration parent, P
3941

4042
public IBoundExpression ResolveType(Declaration module, Declaration parent, ParserRuleContext expression)
4143
{
42-
return _typedBindingContext.Resolve(module, parent, expression, null, StatementResolutionContext.Undefined);
44+
var context = expression;
45+
var opContext = expression as VBAParser.RelationalOpContext;
46+
if (opContext != null && opContext.Parent is VBAParser.ComplexTypeContext)
47+
{
48+
context = opContext.GetChild<VBAParser.LExprContext>(0);
49+
}
50+
return _typedBindingContext.Resolve(module, parent, context, null, StatementResolutionContext.Undefined);
4351
}
4452

4553
public IBoundExpression ResolveProcedurePointer(Declaration module, Declaration parent, ParserRuleContext expression)

Rubberduck.Parsing/Binding/StatementResolutionContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public enum StatementResolutionContext
44
{
55
Undefined,
66
SetStatement,
7-
LetStatement
7+
LetStatement,
8+
DefaultParamValue,
89
}
910
}

Rubberduck.Parsing/Symbols/DeclarationSymbolsListener.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,16 @@ private Declaration CreateDeclaration(
185185
{
186186
var argContext = (VBAParser.ArgContext)context;
187187
var isOptional = argContext.OPTIONAL() != null;
188+
if (isOptional)
189+
{
190+
// if parameter is optional, asTypeName may contain the default value
191+
var complexType = asTypeContext.type().complexType();
192+
if (complexType != null && complexType.expression() is VBAParser.RelationalOpContext)
193+
{
194+
asTypeName = complexType.expression().GetChild(0).GetText();
195+
}
196+
}
197+
188198
var isByRef = argContext.BYREF() != null;
189199
var isParamArray = argContext.PARAMARRAY() != null;
190200
result = new ParameterDeclaration(

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,8 @@ public RubberduckParser(
5656
_comReflector = new ReferencedDeclarationsCollector(_state);
5757

5858
state.ParseRequest += ReparseRequested;
59-
state.StateChanged += StateOnStateChanged;
6059
}
6160

62-
private void StateOnStateChanged(object sender, EventArgs e)
63-
{
64-
Logger.Debug("RubberduckParser handles OnStateChanged ({0})", _state.Status);
65-
}
6661

6762
private void ReparseRequested(object sender, ParseRequestEventArgs e)
6863
{
@@ -466,6 +461,7 @@ private void ParseAsyncInternal(VBComponent component, CancellationToken token,
466461

467462
private void Resolve(CancellationToken token)
468463
{
464+
State.SetStatusAndFireStateChanged(ParserState.Resolving);
469465
var sharedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_resolverTokenSource.Token, token);
470466
// tests expect this to be synchronous :/
471467
//Task.Run(() => ResolveInternal(sharedTokenSource.Token));
@@ -599,8 +595,6 @@ private void ResolveReferences(DeclarationFinder finder, VBComponent component,
599595
public void Dispose()
600596
{
601597
State.ParseRequest -= ReparseRequested;
602-
State.StateChanged -= StateOnStateChanged;
603-
604598
if (_resolverTokenSource != null)
605599
{
606600
_resolverTokenSource.Dispose();

0 commit comments

Comments
 (0)