diff options
author | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2016-04-20 11:34:53 +0200 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2016-06-07 14:18:27 +0200 |
commit | d9702d2173b7813a3a463f2cd93ac19284ca83ff (patch) | |
tree | 68084bbfdb07cbb8f658b885855b3a50463133e1 /src | |
parent | 61fe99b6ad0fcd0a8402435cf15c504ce4b9c4ea (diff) | |
download | dotty-d9702d2173b7813a3a463f2cd93ac19284ca83ff.tar.gz dotty-d9702d2173b7813a3a463f2cd93ac19284ca83ff.tar.bz2 dotty-d9702d2173b7813a3a463f2cd93ac19284ca83ff.zip |
Fix Ycheck: allow assigning fields in static constructors.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/NameOps.scala | 1 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 2 |
3 files changed, 6 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/core/NameOps.scala b/src/dotty/tools/dotc/core/NameOps.scala index 72f89aec3..17af899e9 100644 --- a/src/dotty/tools/dotc/core/NameOps.scala +++ b/src/dotty/tools/dotc/core/NameOps.scala @@ -63,6 +63,7 @@ object NameOps { (if (name.isTermName) n.toTermName else n.toTypeName).asInstanceOf[N] def isConstructorName = name == CONSTRUCTOR || name == TRAIT_CONSTRUCTOR + def isStaticConstructorName = name == STATIC_CONSTRUCTOR def isExceptionResultName = name startsWith EXCEPTION_RESULT_PREFIX def isImplClassName = name endsWith IMPL_CLASS_SUFFIX def isLocalDummyName = name startsWith LOCALDUMMY_PREFIX diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index d3e373dd0..ad454037b 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -594,6 +594,10 @@ object SymDenotations { final def isPrimaryConstructor(implicit ctx: Context) = isConstructor && owner.primaryConstructor == symbol + /** Does this symbol denote the primary constructor of its enclosing class? */ + final def isStaticConstructor(implicit ctx: Context) = + name.isStaticConstructorName + /** Is this a subclass of the given class `base`? */ def isSubClass(base: Symbol)(implicit ctx: Context) = false diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 4f27912f1..aa00fea56 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -481,7 +481,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def canAssign(sym: Symbol) = // allow assignments from the primary constructor to class fields sym.is(Mutable, butNot = Accessor) || ctx.owner.isPrimaryConstructor && !sym.is(Method) && sym.owner == ctx.owner.owner || - ctx.owner.name.isTraitSetterName + ctx.owner.name.isTraitSetterName || ctx.owner.isStaticConstructor lhsCore.tpe match { case ref: TermRef if canAssign(ref.symbol) => assignType(cpy.Assign(tree)(lhs1, typed(tree.rhs, ref.info))) |