Skip to content

Commit

Permalink
Fix for #995: use declaring class for type of constructor contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 28, 2019
1 parent 32535f1 commit e1488a1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,26 @@ final class DSLInferencingTests extends DSLInferencingTestSuite {
}
}

@Test
void testContiribution6() {
createDsls('contribute(currentType("Foo")) { method name:"<init>", type:void, declaringType:Foo }')

String contents = '''\
|class Foo {
| Number bar() {
| }
| def baz() {
| new Foo().bar()
| }
|}
|'''.stripMargin()

inferType(contents, 'bar').with {
assert declaringTypeName == 'Foo'
assert typeName == 'java.lang.Number'
}
}

@Test
void testDelegatesTo1() {
createDsls('contribute(currentType("Foo")) { delegatesTo "Other" }')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ public MethodContributionElement(
@Override
public TypeAndDeclaration lookupType(String name, ClassNode declaringType, ResolverCache resolver) {
if (name.equals(methodName)) {
return new TypeAndDeclaration(returnType(resolver), toMethod(declaringType, resolver), declaringType(declaringType, resolver), doc);
MethodNode node = toMethod(declaringType, resolver);
ClassNode type = (node instanceof ConstructorNode
? node.getDeclaringClass() : node.getReturnType());
return new TypeAndDeclaration(type, node, node.getDeclaringClass(), doc);
}
return null;
}
Expand Down Expand Up @@ -218,8 +221,9 @@ private static Parameter[] toParameters(ParameterContribution[] pcs, ResolverCac
if (pcs == null) {
ps = Parameter.EMPTY_ARRAY;
} else {
ps = new Parameter[pcs.length];
for (int i = 0; i < pcs.length; i++) {
int n = pcs.length;
ps = new Parameter[n];
for (int i = 0; i < n; i += 1) {
ps[i] = pcs[i].toParameter(resolver);
}
}
Expand Down

0 comments on commit e1488a1

Please sign in to comment.