From ad240d06144e868dbe65d68dd169d1e322e28871 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 1 Mar 2020 14:37:42 +0100 Subject: [PATCH] Fix #8397: Make context parameters of given instances protected --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Checking.scala | 4 ++-- tests/pos/i8397.scala | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 tests/pos/i8397.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 08c5aa87b10c..84eca75e84c2 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -3508,7 +3508,7 @@ object Parsers { possibleTemplateStart() val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal)) val vparamss1 = vparamss.map(_.map(vparam => - vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal))) + vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected))) val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil) if tparams.isEmpty && vparamss.isEmpty then ModuleDef(name, templ) else TypeDef(name.toTypeName, templ) diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index a5c582fecd5d..7e49cb53eafa 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -510,8 +510,8 @@ object Checking { var tp1 = if (isLeaked(tp.symbol)) { errors = - (() => em"non-private ${sym.showLocated} refers to private ${tp.symbol}\nin its type signature ${sym.info}") :: - errors + (() => em"non-private ${sym.showLocated} refers to private ${tp.symbol}\nin its type signature ${sym.info}") + :: errors tp } else mapOver(tp) diff --git a/tests/pos/i8397.scala b/tests/pos/i8397.scala new file mode 100644 index 000000000000..e6420ecdf0d7 --- /dev/null +++ b/tests/pos/i8397.scala @@ -0,0 +1,3 @@ +given foo(using x: Int) as AnyRef: + type T = x.type +