chapel icon indicating copy to clipboard operation
chapel copied to clipboard

dyno: semantic checks in generic initializers are printed twice

Open DanilaFe opened this issue 10 months ago • 0 comments

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).

DanilaFe avatar Apr 22 '24 21:04 DanilaFe