Skip to content

Commit 026edcc

Browse files
authored
Merge pull request #18438 from Maxrimus/release/1.25
Release/1.25 [Reviewed by @mppf ] Cherrypicked commits: #18428 #18433
2 parents 53375b4 + edc9b74 commit 026edcc

5 files changed

+68
-21
lines changed

Diff for: compiler/resolution/virtualDispatch.cpp

+27-21
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ static void addToVirtualMaps(FnSymbol* pfn,
243243
FnSymbol* cfn) {
244244

245245
FnSymbol* fn = getInstantiatedFunction(pfn, ct, cfn);
246+
246247
resolveOverride(pfn, fn);
247248
}
248249

@@ -285,27 +286,7 @@ static void collectMethods(FnSymbol* pfn,
285286
}
286287
}
287288
if (possibleSignatureMatch(pfn, cfn) == true) {
288-
if (cfn->retTag == RET_PARAM ||
289-
cfn->retTag == RET_TYPE) {
290-
USR_FATAL_CONT(cfn,
291-
"param default arguments in overridden methods "
292-
"are not yet supported.");
293-
} else {
294-
methods.push_back(cfn);
295-
}
296-
297-
// check to see if we are using defaulted actual fns
298-
// for any of the formals in pfn. If so, make sure the
299-
// corresponding ones exist for the child.
300-
int nUserFormals = getNumUserFormals(pfn);
301-
for (int i = 1; i <= nUserFormals; i++) {
302-
ArgSymbol* pformal = getUserFormal(pfn, i);
303-
ArgSymbol* cformal = getUserFormal(cfn, i);
304-
FnSymbol* pDefFn = findExistingDefaultedActualFn(pfn, pformal);
305-
if (pDefFn) {
306-
getOrCreateDefaultedActualFn(cfn, cformal);
307-
}
308-
}
289+
methods.push_back(cfn);
309290
}
310291
}
311292
}
@@ -469,6 +450,31 @@ static void resolveOverride(FnSymbol* pfn, FnSymbol* cfn) {
469450

470451
resolveFunction(cfn);
471452

453+
// check to see if we are using defaulted actual fns
454+
// for any of the formals in pfn. If so, make sure the
455+
// corresponding ones exist for the child.
456+
int nUserFormals = getNumUserFormals(pfn);
457+
for (int i = 1; i <= nUserFormals; i++) {
458+
ArgSymbol* pFormal = getUserFormal(pfn, i);
459+
ArgSymbol* cFormal = getUserFormal(cfn, i);
460+
FnSymbol* pDefFn = findExistingDefaultedActualFn(pfn, pFormal);
461+
if (pDefFn) {
462+
FnSymbol* cDefFn = getOrCreateDefaultedActualFn(cfn, cFormal);
463+
if (cDefFn) {
464+
if (pFormal->hasFlag(FLAG_INSTANTIATED_PARAM) &&
465+
cFormal->hasFlag(FLAG_INSTANTIATED_PARAM)) {
466+
USR_FATAL_CONT(cfn, "param default arguments in overridden methods"
467+
" are not yet supported.");
468+
}
469+
if (pFormal->hasFlag(FLAG_TYPE_VARIABLE) &&
470+
cFormal->hasFlag(FLAG_TYPE_VARIABLE)) {
471+
USR_FATAL_CONT(cfn, "type default arguments in overridden methods"
472+
" are not yet supported.");
473+
}
474+
}
475+
}
476+
}
477+
472478
if (checkOverrides(cfn) &&
473479
!ignoreOverrides(cfn) &&
474480
!cfn->hasFlag(FLAG_OVERRIDE)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
default-argument-class-override3b.chpl:11: error: type default arguments in overridden methods are not yet supported.
2+
default-argument-class-override3b.chpl:11: error: type default arguments in overridden methods are not yet supported.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
proc f() type { return int; }
2+
proc g() type { return real; }
3+
4+
class Parent {
5+
proc method(type arg = f()) {
6+
writeln("in Parent.method arg=", arg:string);
7+
}
8+
}
9+
10+
class Child : Parent {
11+
override proc method(type arg = g()) {
12+
writeln("in Child.method arg=", arg:string);
13+
}
14+
}
15+
16+
proc main() {
17+
var x:Parent = new Child();
18+
x.method();
19+
20+
var y = new Child();
21+
y.method();
22+
23+
var z = new Parent();
24+
z.method();
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
bug: dynamically dispatched methods with default type arguments wrong
2+
3+
#15164
4+
5+
This test demonstrates that when methods are dynamically dispatched
6+
and have type arguments with defaults, the compiler doesn't use the
7+
default from the method that was chosen dynamically, but the one based
8+
on the static type. This is because we implement default arguments
9+
as methods currently, and can't dynamically dispatch type methods.
10+
Yet we have to statically invoke the default arguments in order to
11+
fulfill the `type` nature of the arguments.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
in Child.method arg=real(64)
2+
in Child.method arg=real(64)
3+
in Parent.method arg=int(64)

0 commit comments

Comments
 (0)