Skip to content

Commit 2f36da4

Browse files
committed
Set explicit nulls in CompilationUnitInfo symbols from source
1 parent 91f8e3a commit 2f36da4

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

compiler/src/dotty/tools/dotc/core/CompilationUnitInfo.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ import dotty.tools.tasty.TastyVersion
99
* the class containing this symbol was generated,
1010
* null if not applicable.
1111
* @param tastyVersion The TASTy version (major, minor, experimental)
12-
* @param tastyExplicitNulls Was this compilation unit compiled with explicit nulls?
12+
* @param explicitNulls This compilation unit has explicit nulls enabled?
1313
*/
1414
class CompilationUnitInfo(
1515
val associatedFile: AbstractFile,
1616
val tastyVersion: Option[TastyVersion],
17-
val tastyExplicitNulls: Boolean
17+
val explicitNulls: Boolean
1818
) {
1919

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

2424
object CompilationUnitInfo:
25-
def apply(assocFile: AbstractFile | Null): CompilationUnitInfo | Null =
25+
def apply(assocFile: AbstractFile | Null, explicitNulls: Boolean = false): CompilationUnitInfo | Null =
2626
if assocFile == null then null
2727
else new CompilationUnitInfo(
2828
assocFile,
2929
tastyVersion = None,
30-
tastyExplicitNulls = false // TODO track explicit nulls for current compilation units (not only TASTy)
30+
explicitNulls = explicitNulls,
3131
)

compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
433433
new CompilationUnitInfo(
434434
tastyFile,
435435
tastyVersion = Some(tastyVersion),
436-
tastyExplicitNulls = attributes.explicitNulls,
436+
explicitNulls = attributes.explicitNulls,
437437
)
438438

439439
def description(using Context): String = "TASTy file " + tastyFile.toString

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ object Symbols {
288288
if compUnitInfo == null then None
289289
else compUnitInfo.tastyVersion
290290

291+
/** If this class has explicit nulls enabled */
292+
def explicitNulls(using Context): Boolean =
293+
val compUnitInfo = compilationUnitInfo
294+
compUnitInfo != null && compUnitInfo.explicitNulls
295+
291296
/** The class file from which this class was generated, null if not applicable. */
292297
final def binaryFile(using Context): AbstractFile | Null = {
293298
val file = associatedFile

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class Namer { typer: Typer =>
250250
val cls =
251251
createOrRefine[ClassSymbol](tree, name, flags, ctx.owner,
252252
cls => adjustIfModule(new ClassCompleter(cls, tree)(ctx), tree),
253-
newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, CompilationUnitInfo(ctx.source.file)))
253+
newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, CompilationUnitInfo(ctx.source.file, explicitNulls = ctx.explicitNulls)))
254254
cls.completer.asInstanceOf[ClassCompleter].init()
255255
cls
256256
case tree: MemberDef =>

0 commit comments

Comments
 (0)