chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.79k stars 421 forks source link

what should R() do if R has some generic fields with defaults? #22714

Open mppf opened 1 year ago

mppf commented 1 year ago

Summary of Problem

I am expecting that R() will run the type constructor for a generic record R, and that the type constructor has a default formal for each generic field with a default value. But, this does not seem to be happening for types that are generic but have defaults for some fields.

Steps to Reproduce

Source Code:

record R {
  type t;
  param rank: int = 2;
}

proc printType(type t) {
  writeln(t:string);
  if t.t == ? then
    writeln(".t is uninstantiated");
  else
    writeln(".t: ", t.t:string);
  if t.rank == ? then
    writeln(".rank is uninstantiated");
  else
    writeln(".rank: ", t.rank:string);
}

printType(R);
printType(R());
R
.t is uninstantiated
.rank is uninstantiated
R
.t is uninstantiated
.rank is uninstantiated

I would expect that it output

R
.t is uninstantiated
.rank is uninstantiated
R
.t is uninstantiated
.rank: 2

Associated Future Test(s):

It's not technically a future, but PR #22718 added a warning for this case & a test of that warning

test/types/type_variables/ferguson/some-defaults-ignored.chpl

bradcray commented 11 months ago

@mppf: This issue slipped past me when it was filed. Is it still relevant? What labels should be attached to it? (e.g., bug vs. 2.0?)

mppf commented 11 months ago

It's still relevant and it's related to #18214. I'm not sure what the program shown should do in terms of language design (so I'm not even sure if it's a bug).

However, it is not an issue for Chapel 2.0, because the compiler warns of unstable behavior in this case.