Skip to content

Trees after typer losing information #15750

@tgodzik

Description

@tgodzik

Compiler version

3.1.3

Minimized code

object Main {
  def foo: ArrayBuffer[Int] = ???
}

ArrayBuffer is missing from imports.

Output

Parser tree

PackageDef(
  pid = Ident(name = <empty>),
  stats = List(
    ModuleDef(
      name = Main,
      impl = Template(
        constr = DefDef(
          name = <init>,
          paramss = List(),
          tpt = TypeTree,
          preRhs = Thicket(trees = List())
        ),
        parentsOrDerived = List(),
        self = ValDef(name = _, tpt = Thicket(trees = List()), preRhs = Thicket(trees = List())),
        preBody = List(
          DefDef(
            name = foo,
            paramss = List(),
            tpt = AppliedTypeTree(tpt = Ident(name = ArrayBuffer), args = List(Ident(name = Int))),
            preRhs = Ident(name = ???)
          )
        )
      )
    )
  )
)

Notice tpt = AppliedTypeTree(tpt = Ident(name = ArrayBuffer), args = List(Ident(name = Int))), <- AppliedTypeTree is available.

Typed tree though:

 tree = TypeDef(
        name = Main$,
        rhs = Template(
          constr = DefDef(
            name = <init>,
            paramss = List(List()),
            tpt = TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Unit)],
            preRhs = Thicket(trees = List())
          ),
          parentsOrDerived = List(
            Apply(
              fun = Select(
                qualifier = New(
                  tpt = TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),class Object)]
                ),
                name = <init>
              ),
              args = List()
            )
          ),
          self = ValDef(
            name = _,
            tpt = SingletonTypeTree(ref = Ident(name = Main)),
            preRhs = Thicket(trees = List())
          ),
          preBody = List(
            DefDef(
              name = foo,
              paramss = List(),
              tpt = Ident(name = ArrayBuffer),
              preRhs = Ident(name = ???)
            )
          )
        )
      ),

Notice that the tpt of the DefDef is tpt = Ident(name = ArrayBuffer),

Seems that if the type is not available then we are missing TypeApply, which is useful for the IDE to figure out if we need to insert []

Expectation

TypeApply should still be available in tpt of DefDef. It might be an error type, but it should be available there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions