Skip to content

Field promotion doesn't work when element type is not in scope #26938

@DanilaFe

Description

@DanilaFe

Starting with the following piece of the field promotion spec:

record Point {
  var x: real;
  var y: real;
}
var A: [1..5] Point = [i in 1..5] new Point(x=i, y=i);
var X = A.x;
A.y = 1.0;

   
writeln(X);
writeln(A);

I was checking how the compiler resolves / finds the getter methods for Point while resolving the promoted call A.x (etc.). I observed that the compiler only looks in the current scope (and in the scope of the receiver, the array). This means that if the type is not visible in scope, promotion fails. I suspect this is a bug, because calling .x on a value of type Point -- without bringing the type itself into scope -- works fine. The below example demonstrates this.

module M1 {
  record Point {
    var x: real;
    var y: real;
  }
  var A: [1..5] Point;
  var P: Point;
}

module M2 {
  import M1.{A, P};
  var myX = P.x; // works fine
  var B = A.x; // doesn't compile

  proc main() {
    writeln(myX);
    writeln(B);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions