chapel-lang / chapel

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

dyno: semantic checks in generic initializers are printed twice #24900

Open DanilaFe opened 3 weeks ago

DanilaFe commented 3 weeks ago

Reproducer:

record r {
    var x: int;
    var y: int;

    proc init(type arg) {
        this.y = 10;
        this.x = 32;
    }
}

var x = new r(int);

Prints:

─── error in doubleinit.chpl:7 ───
  Field "x" initialized out of order

─── error in doubleinit.chpl:7 ───
  Field "x" initialized out of order

I suspect the reason is that we try to specifically resolve the initializer's body a second time to ensure that the semantic checks run. However, in the generic case, instantiations' bodies are already resolved, so we have already emitted the error. I've tried adjusting the following code naively:

  // Make sure that we are resolving initializer bodies even when the
  // signature is concrete, because there are semantic checks.
  if (isCallInfoForInitializer(ci) && mostSpecific.numBest() == 1) {
    auto candidateFn = mostSpecific.only().fn();
    CHPL_ASSERT(isTfsForInitializer(candidateFn));

    // TODO: Can we move this into the 'InitVisitor'?
    if (!candidateFn->untyped()->isCompilerGenerated()) {
      std::ignore = resolveInitializer(context, candidateFn, inScopes.poiScope());
    }
  }

But didn't get it to work as expected after 30 seconds, so am opening an issue and will come back to this (unless someone else wants to steal in the meantime).