Skip to content

Commit

Permalink
Set explicit nulls in CompilationUnitInfo symbols from source
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Nov 22, 2023
1 parent ada4552 commit b00bb30
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/CompilationUnitInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ import dotty.tools.tasty.TastyVersion
* the class containing this symbol was generated,
* null if not applicable.
* @param tastyVersion The TASTy version (major, minor, experimental)
* @param tastyExplicitNulls Was this compilation unit compiled with explicit nulls?
* @param explicitNulls This compilation unit has explicit nulls enabled?
*/
class CompilationUnitInfo(
val associatedFile: AbstractFile,
val tastyVersion: Option[TastyVersion],
val tastyExplicitNulls: Boolean
val explicitNulls: Boolean
) {

override def toString(): String =
s"CompilationUnitInfo($associatedFile, $tastyVersion)"
}

object CompilationUnitInfo:
def apply(assocFile: AbstractFile | Null): CompilationUnitInfo | Null =
def apply(assocFile: AbstractFile | Null, explicitNulls: Boolean = false): CompilationUnitInfo | Null =
if assocFile == null then null
else new CompilationUnitInfo(
assocFile,
tastyVersion = None,
tastyExplicitNulls = false // TODO track explicit nulls for current compilation units (not only TASTy)
explicitNulls = explicitNulls,
)
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
new CompilationUnitInfo(
tastyFile,
tastyVersion = Some(tastyVersion),
tastyExplicitNulls = attributes.explicitNulls,
explicitNulls = attributes.explicitNulls,
)

def description(using Context): String = "TASTy file " + tastyFile.toString
Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ object Symbols {
if compUnitInfo == null then None
else compUnitInfo.tastyVersion

/** If this class has explicit nulls enabled */
def explicitNulls(using Context): Boolean =
val compUnitInfo = compilationUnitInfo
compUnitInfo != null && compUnitInfo.explicitNulls

/** The class file from which this class was generated, null if not applicable. */
final def binaryFile(using Context): AbstractFile | Null = {
val file = associatedFile
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class Namer { typer: Typer =>
val cls =
createOrRefine[ClassSymbol](tree, name, flags, ctx.owner,
cls => adjustIfModule(new ClassCompleter(cls, tree)(ctx), tree),
newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, CompilationUnitInfo(ctx.source.file)))
newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, CompilationUnitInfo(ctx.source.file, explicitNulls = ctx.explicitNulls)))
cls.completer.asInstanceOf[ClassCompleter].init()
cls
case tree: MemberDef =>
Expand Down

0 comments on commit b00bb30

Please sign in to comment.