diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 306b12c6578e..f63ff1c9013d 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1935,7 +1935,9 @@ object SymDenotations { def hasTastyVersion: Boolean = myTastyVersion != -1 def tastyVersion: Long = - require(hasTastyVersion) + println("sym id of " + name + " is " + symbol.id) + println("checking hasTastyVersion " + name + " " + hasTastyVersion + " " + System.identityHashCode(this)) + require(hasTastyVersion, s"tasty version of $name not set") myTastyVersion def tastyMajorVersion: Int = (tastyVersion >>> (28 * 2)).toInt @@ -2659,6 +2661,7 @@ object SymDenotations { initTastyVersion: Long = -1)(using Context): SymDenotation = { val result = if (symbol.isClass) + try println(s"${symbol.name} isClass") catch case _ => () if (initFlags.is(Package)) new PackageClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin, initTastyVersion) else new ClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin, initTastyVersion) else new SymDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin) diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index 8f47d9f80a6c..ea3ff0472ab7 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -366,9 +366,10 @@ object Symbols { val associatedFile1 = if (associatedFile == null) owner.associatedFile else associatedFile if isClass then - newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1) + val d = denot.asClass.tastyVersion + newClassSymbol(owner, name.asTypeName, flags, _ => info, privateWithin, coord1, associatedFile1, initTastyVersion = d) else - newSymbol(owner, name, flags, info, privateWithin, coord1) + newSymbol(owner, name, flags, info, privateWithin, coord1, initTastyVersion = -1) // AR } // -------- Printing -------------------------------------------------------- @@ -519,7 +520,7 @@ object Symbols { privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord, nestingLevel: Int = ctx.nestingLevel, - initTastyVersion: Long = -1): Symbol { type ThisName = N } = { + initTastyVersion: Long): Symbol { type ThisName = N } = { val sym = new Symbol(coord, ctx.base.nextSymId, nestingLevel).asInstanceOf[Symbol { type ThisName = N }] val denot = SymDenotation(sym, owner, name, flags, info, privateWithin, initTastyVersion) sym.denot = denot @@ -537,7 +538,7 @@ object Symbols { privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord, assocFile: AbstractFile | Null = null, - initTastyVersion: Long = -1)(using Context): ClassSymbol + initTastyVersion: Long)(using Context): ClassSymbol = { val cls = new ClassSymbol(coord, assocFile, ctx.base.nextSymId, ctx.nestingLevel) val denot = SymDenotation(cls, owner, name, flags, infoFn(cls), privateWithin, initTastyVersion) @@ -555,11 +556,12 @@ object Symbols { selfInfo: Type = NoType, privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord, - assocFile: AbstractFile | Null = null)(using Context): ClassSymbol = + assocFile: AbstractFile | Null = null, + initTastyVersion: Long)(using Context): ClassSymbol = newClassSymbol( owner, name, flags, ClassInfo(owner.thisType, _, parents, decls, selfInfo), - privateWithin, coord, assocFile) + privateWithin, coord, assocFile, initTastyVersion) /** Same as `newCompleteClassSymbol` except that `parents` can be a list of arbitrary * types which get normalized into type refs and parameter bindings. @@ -572,7 +574,8 @@ object Symbols { selfInfo: Type = NoType, privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord, - assocFile: AbstractFile | Null = null)(using Context): ClassSymbol = { + assocFile: AbstractFile | Null = null, + initTastyVersion: Long)(using Context): ClassSymbol = { def completer = new LazyType { def complete(denot: SymDenotation)(using Context): Unit = { val cls = denot.asClass.classSymbol @@ -580,7 +583,7 @@ object Symbols { denot.info = ClassInfo(owner.thisType, cls, parentTypes.map(_.dealias), decls, selfInfo) } } - newClassSymbol(owner, name, flags, completer, privateWithin, coord, assocFile) + newClassSymbol(owner, name, flags, completer, privateWithin, coord, assocFile, initTastyVersion) } def newRefinedClassSymbol(coord: Coord = NoCoord)(using Context): ClassSymbol = @@ -598,15 +601,16 @@ object Symbols { infoFn: (TermSymbol, ClassSymbol) => Type, // typically a ModuleClassCompleterWithDecls privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord, - assocFile: AbstractFile | Null = null)(using Context): TermSymbol + assocFile: AbstractFile | Null = null, + initTastyVersion: Long)(using Context): TermSymbol = { val base = owner.thisType val modclsFlags = clsFlags | ModuleClassCreationFlags val modclsName = name.toTypeName.adjustIfModuleClass(modclsFlags) val module = newSymbol( - owner, name, modFlags | ModuleValCreationFlags, NoCompleter, privateWithin, coord) + owner, name, modFlags | ModuleValCreationFlags, NoCompleter, privateWithin, coord, initTastyVersion = initTastyVersion) val modcls = newClassSymbol( - owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, assocFile) + owner, modclsName, modclsFlags, infoFn(module, _), privateWithin, coord, assocFile, initTastyVersion) module.info = if (modcls.isCompleted) TypeRef(owner.thisType, modcls) else new ModuleCompleter(modcls) @@ -627,12 +631,13 @@ object Symbols { decls: Scope, privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord, - assocFile: AbstractFile | Null = null)(using Context): TermSymbol = + assocFile: AbstractFile | Null = null, + initTastyVersion: Long)(using Context): TermSymbol = newModuleSymbol( owner, name, modFlags, clsFlags, (module, modcls) => ClassInfo( owner.thisType, modcls, parents, decls, TermRef(owner.thisType, module)), - privateWithin, coord, assocFile) + privateWithin, coord, assocFile, initTastyVersion) /** Same as `newCompleteModuleSymbol` except that `parents` can be a list of arbitrary * types which get normalized into type refs and parameter bindings. @@ -646,18 +651,20 @@ object Symbols { decls: Scope, privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord, - assocFile: AbstractFile | Null = null)(using Context): TermSymbol = { + assocFile: AbstractFile | Null = null, + initTastyVersion: Long)(using Context): TermSymbol = { def completer(module: Symbol) = new LazyType { def complete(denot: SymDenotation)(using Context): Unit = { val cls = denot.asClass.classSymbol val decls = newScope denot.info = ClassInfo(owner.thisType, cls, parentTypes.map(_.dealias), decls, TermRef(owner.thisType, module)) + // TODO? set tastyVersion } } newModuleSymbol( owner, name, modFlags, clsFlags, (module, modcls) => completer(module), - privateWithin, coord, assocFile) + privateWithin, coord, assocFile, initTastyVersion) } /** Create a package symbol with associated package class @@ -794,7 +801,7 @@ object Symbols { def newErrorSymbol(owner: Symbol, name: Name, msg: Message)(using Context): Symbol = { val errType = ErrorType(msg) newSymbol(owner, name, SyntheticArtifact, - if (name.isTypeName) TypeAlias(errType) else errType) + if (name.isTypeName) TypeAlias(errType) else errType, initTastyVersion = -1) } /** Map given symbols, subjecting their attributes to the mappings diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 481768fb4dbf..84cf8ba0ce7e 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -498,6 +498,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas denot.setPrivateWithin(privateWithin) denot.info = completer + denot.tastyVersion = 0 denot.symbol } @@ -549,6 +550,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas if (flags.is(TypeParam)) flags1 |= owner.typeParamCreationFlags newSymbol(owner, name1, flags1, localMemberUnpickler, privateWithin, coord = start) case CLASSsym => +// println(s"name: $name") + if (isClassRoot) completeRoot( classRoot, rootClassUnpickler(start, classRoot.symbol, NoSymbol, infoRef), privateWithin) @@ -564,7 +567,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas .suchThat(_.is(Module)).symbol) else unpickler } - newClassSymbol(owner, name.asTypeName, flags, completer, privateWithin, coord = start) + newClassSymbol(owner, name.asTypeName, flags, completer, privateWithin, coord = start, initTastyVersion = 0) +// newClassSymbol(owner, name.asTypeName, flags, completer, privateWithin, coord = start) } case VALsym => newSymbol(owner, name.asTermName, flags, localMemberUnpickler, privateWithin, coord = start) @@ -576,7 +580,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas new LocalUnpickler().withModuleClass( owner.info.decls.lookup(name.moduleClassName) .suchThat(_.is(Module)).symbol) - , privateWithin, coord = start) + , privateWithin, coord = start, initTastyVersion = 0) case _ => errorBadSignature("bad symbol tag: " + tag) }) diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 0d08141111cd..85e1591cd0bf 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -237,26 +237,39 @@ class Namer { typer: Typer => prev.flags = flags1 prev.info = infoFn(prev.asInstanceOf[S]) prev.setPrivateWithin(privateWithin) + val tastyVersion = (TastyFormat.MajorVersion.toLong << (28 * 2)) + | (TastyFormat.MinorVersion.toLong << 28) + | TastyFormat.ExperimentalVersion.toLong + if prev.isClass then prev.asClass.classDenot.tastyVersion = tastyVersion prev } else symFn(flags1, infoFn, privateWithin) recordSym(sym, tree) } - tree match { + // TODO Move + val currentTastyVersion = (TastyFormat.MajorVersion.toLong << (28 * 2)) + | (TastyFormat.MinorVersion.toLong << 28) + | TastyFormat.ExperimentalVersion.toLong + +// if tree.className.contains("Some") then +// println(i"creating symbol for ${tree.className}") + val res = tree match { case tree: TypeDef if tree.isClassDef => +// if tree.toString.contains("Some") then +// println(s"creating symbol for class ${tree.name}") val flags = checkFlags(tree.mods.flags) val name = checkNoConflict(tree.name, flags.is(Private), tree.span).asTypeName - val tastyVersion = (TastyFormat.MajorVersion.toLong << (28 * 2)) - | (TastyFormat.MinorVersion.toLong << 28) - | TastyFormat.ExperimentalVersion.toLong val cls = createOrRefine[ClassSymbol](tree, name, flags, ctx.owner, cls => adjustIfModule(new ClassCompleter(cls, tree)(ctx), tree), - newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, ctx.source.file, tastyVersion)) + newClassSymbol(ctx.owner, name, _, _, _, tree.nameSpan, ctx.source.file, currentTastyVersion)) cls.completer.asInstanceOf[ClassCompleter].init() cls case tree: MemberDef => + if tree.toString.contains("Some") then + println(s"creating symbol for member ${tree.name}") + var flags = checkFlags(tree.mods.flags) val name = checkNoConflict(tree.name, flags.is(Private), tree.span) tree match @@ -295,13 +308,21 @@ class Namer { typer: Typer => case tree: TypeDef => TypeDefCompleter(tree)(cctx) case _ => Completer(tree)(cctx) val info = adjustIfModule(completer, tree) - createOrRefine[Symbol](tree, name, flags, ctx.owner, _ => info, - (fs, _, pwithin) => newSymbol(ctx.owner, name, fs, info, pwithin, tree.nameSpan)) + val s = createOrRefine[Symbol](tree, name, flags, ctx.owner, _ => info, + (fs, _, pwithin) => newSymbol(ctx.owner, name, fs, info, pwithin, tree.nameSpan, initTastyVersion = currentTastyVersion)) + + s case tree: Import => +// if tree.toString.contains("Some") then +// println(s"creating symbol for import ${tree.className}") recordSym(newImportSymbol(ctx.owner, Completer(tree)(ctx), tree.span), tree) case _ => +// if tree.toString.contains("Some") then +// println(s"creating symbol for _ ${tree.className}") NoSymbol } +// println(s"creating symbol $res") + res } /** If `sym` exists, enter it in effective scope. Check that diff --git a/tests/pos/i12508c.scala b/tests/pos/i12508c.scala index 97c81cd61fcd..4e7bf7b63a10 100644 --- a/tests/pos/i12508c.scala +++ b/tests/pos/i12508c.scala @@ -1,12 +1,39 @@ -def fun(a: Any, b: Any = 2): Any = ??? +//def fun(a: Any, b: Any = 2): Any = ??? +def fun(a: Any, b: Any): Any = ??? def test = + +// val a1 = { +// enum Option1[+X]: +// case Some1(x: X) +// case None1 +// if ??? then Option1.Some1(1) else Option1.None1 +// } +// fun( +// b = println(1), +// a = a1 +// ) // works + fun( - b = println(1), a = { - enum Option[+X]: - case Some(x: X) - case None - if ??? then Option.Some(1) else Option.None - } - ) \ No newline at end of file + enum Option3[+X]: + case Some3(x: X) + case None3 + if ??? then Option3.Some3(1) else Option3.None3 + }, + b = println(1), + ) // works + +// fun( +// b = println(1), +// a = { +// enum Option2[+X]: +// case Some2(x: X) +// case None2 +// +// import Option2.* +// summon[deriving.Mirror.Of[Some2[Int]]] +// +// if ??? then Option2.Some2(1) else Option2.None2 +// } +// ) // fails \ No newline at end of file