Skip to content

Commit

Permalink
Strip parentheses from AsTypeName of array returning functions and pr…
Browse files Browse the repository at this point in the history
…operties
  • Loading branch information
MDoerner committed Aug 24, 2019
1 parent 3a915a4 commit 617b27f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Expand Up @@ -93,6 +93,7 @@ private IEnumerable<IAnnotation> FindGeneralAnnotations(int firstLine)

var isByRef = argContext.BYREF() != null || argContext.BYVAL() == null;
var isParamArray = argContext.PARAMARRAY() != null;

result = new ParameterDeclaration(
new QualifiedMemberName(_qualifiedModuleName, identifierName),
_parentDeclaration,
Expand Down Expand Up @@ -385,9 +386,12 @@ public override void EnterFunctionStmt(VBAParser.FunctionStmtContext context)
: asTypeClause.type().GetText()
: SymbolList.TypeHintToTypeName[typeHint];
var isArray = asTypeName.EndsWith("()");
var actualAsTypeName = isArray && asTypeName.EndsWith("()")
? asTypeName.Substring(0, asTypeName.Length - 2)
: asTypeName;
var declaration = CreateDeclaration(
name,
asTypeName,
actualAsTypeName,
accessibility,
DeclarationType.Function,
context,
Expand Down Expand Up @@ -417,9 +421,12 @@ public override void EnterPropertyGetStmt(VBAParser.PropertyGetStmtContext conte
: asTypeClause.type().GetText()
: SymbolList.TypeHintToTypeName[typeHint];
var isArray = asTypeClause != null && asTypeClause.type().LPAREN() != null;
var actualAsTypeName = isArray && asTypeName.EndsWith("()")
? asTypeName.Substring(0, asTypeName.Length - 2)
: asTypeName;
var declaration = CreateDeclaration(
name,
asTypeName,
actualAsTypeName,
accessibility,
DeclarationType.PropertyGet,
context,
Expand Down
46 changes: 46 additions & 0 deletions RubberduckTests/Grammar/ResolverTests.cs
Expand Up @@ -2730,6 +2730,52 @@ End Sub
}
}

[Category("Grammar")]
[Category("Resolver")]
[Test]
public void FunctionTypeNameIsElementTypeName()
{
var code = @"
Public Function bar() As Long()
End Function
";
using (var state = Resolve(code))
{

var declaration = state.DeclarationFinder
.UserDeclarations(DeclarationType.Function)
.Single();

var expectedTypeName = "Long";
var actualAsTypeName = declaration.AsTypeName;

Assert.AreEqual(expectedTypeName, actualAsTypeName);
}
}

[Category("Grammar")]
[Category("Resolver")]
[Test]
public void PropertyGetTypeNameIsElementTypeName()
{
var code = @"
Public Property Get bar() As Long()
End Property
";
using (var state = Resolve(code))
{

var declaration = state.DeclarationFinder
.UserDeclarations(DeclarationType.PropertyGet)
.Single();

var expectedTypeName = "Long";
var actualAsTypeName = declaration.AsTypeName;

Assert.AreEqual(expectedTypeName, actualAsTypeName);
}
}

[Category("Grammar")]
[Category("Resolver")]
[Test]
Expand Down

0 comments on commit 617b27f

Please sign in to comment.