Skip to content

Commit e31d40b

Browse files
committed
Read SourceFile attribute from classfile in unpickling
Note that we cannot use `classRoot.unforcedAnnotation(defn.SourceFileAnnot)` because it's not loaded yet.
1 parent ab01ce3 commit e31d40b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import dotty.tools.tasty.{ TastyReader, TastyHeaderUnpickler }
88
import Contexts._, Symbols._, Types._, Names._, StdNames._, NameOps._, Scopes._, Decorators._
99
import SymDenotations._, unpickleScala2.Scala2Unpickler._, Constants._, Annotations._, util.Spans._
1010
import NameKinds.DefaultGetterName
11-
import ast.tpd._
11+
import ast.tpd._, util._
1212
import java.io.{ ByteArrayInputStream, ByteArrayOutputStream, DataInputStream, IOException }
1313

1414
import java.lang.Integer.toHexString
@@ -728,6 +728,12 @@ class ClassfileParser(
728728
i < attrs
729729
}
730730

731+
val sourceFile: SourceFile =
732+
if scan(tpnme.SourceFileATTR) then
733+
val attrLen = in.nextInt
734+
SourceFile.virtual(pool.getName(in.nextChar).toString, "")
735+
else NoSource
736+
731737
def unpickleScala(bytes: Array[Byte]): Some[Embedded] = {
732738
val allowed = ctx.settings.Yscala2Unpickler.value
733739

@@ -750,7 +756,7 @@ class ClassfileParser(
750756

751757
def unpickleTASTY(bytes: Array[Byte]): Some[Embedded] = {
752758
val unpickler = new tasty.DottyUnpickler(bytes)
753-
unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule))(ctx.withSource(util.NoSource))
759+
unpickler.enter(roots = Set(classRoot, moduleRoot, moduleRoot.sourceModule))(ctx.withSource(sourceFile))
754760
Some(unpickler)
755761
}
756762

0 commit comments

Comments
 (0)