Skip to content

Commit 25cf4ed

Browse files
authored
Merge branch 'lampepfl:main' into show-context-for-inline-safe-init
2 parents 18300d0 + c04f566 commit 25cf4ed

File tree

34 files changed

+432
-456
lines changed

34 files changed

+432
-456
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,6 @@
247247
[submodule "community-build/community-projects/scalacheck-forward-compat"]
248248
path = community-build/community-projects/scalacheck-forward-compat
249249
url = https://github.com/dotty-staging/scalacheck
250+
[submodule "community-build/community-projects/http4s"]
251+
path = community-build/community-projects/http4s
252+
url = https://github.com/dotty-staging/http4s.git
Submodule http4s added at fc0a18d

community-build/src/scala/dotty/communitybuild/projects.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,14 @@ object projects:
791791
dependencies = () => List(cats, disciplineMunit)
792792
)
793793

794+
lazy val http4s = SbtCommunityProject(
795+
project = "http4s",
796+
sbtTestCommand = "tests/test; server/test; client/test; ember-core/test; ember-server/test; ember-client/test; circe/test",
797+
sbtPublishCommand = "publishLocal",
798+
scalacOptions = SbtCommunityProject.scalacOptions.filter(_ != "-Ysafe-init"),
799+
dependencies = () => List(cats, catsEffect3, fs2, disciplineMunit, scalacheckEffect)
800+
)
801+
794802
end projects
795803

796804
lazy val forwardCompatMapping = Map[CommunityProject, CommunityProject](
@@ -892,7 +900,9 @@ def allProjects = List(
892900
projects.jacksonModuleScala,
893901
projects.specs2,
894902
projects.coop,
895-
projects.coopForwardCompat
903+
projects.coopForwardCompat,
904+
projects.spire,
905+
projects.http4s
896906
)
897907

898908
lazy val projectMap = allProjects.groupBy(_.project)

community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class CommunityBuildTestB:
5252
@Test def scodecBits = projects.scodecBits.run()
5353
@Test def simulacrumScalafixAnnotations = projects.simulacrumScalafixAnnotations.run()
5454
@Test def spire = projects.spire.run()
55+
@Test def http4s = projects.http4s.run()
5556
end CommunityBuildTestB
5657

5758
@Category(Array(classOf[TestCategory]))

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4563,14 +4563,7 @@ class JSCodeGen()(using genCtx: Context) {
45634563
val module = annot.argumentConstantString(0).getOrElse {
45644564
unexpected("could not read the module argument as a string literal")
45654565
}
4566-
val path = annot.argumentConstantString(1).fold {
4567-
if (annot.arguments.sizeIs < 2)
4568-
parsePath(sym.defaultJSName)
4569-
else
4570-
Nil
4571-
} { pathName =>
4572-
parsePath(pathName)
4573-
}
4566+
val path = annot.argumentConstantString(1).fold[List[String]](Nil)(parsePath)
45744567
val importSpec = Import(module, path)
45754568
annot.argumentConstantString(2).fold[js.JSNativeLoadSpec] {
45764569
importSpec

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ object Completion {
7878
Mode.None
7979
}
8080

81+
/** When dealing with <errors> in varios palces we check to see if they are
82+
* due to incomplete backticks. If so, we ensure we get the full prefix
83+
* including the backtick.
84+
*
85+
* @param content The source content that we'll check the positions for the prefix
86+
* @param start The start position we'll start to look for the prefix at
87+
* @param end The end position we'll look for the prefix at
88+
* @return Either the full prefix including the ` or an empty string
89+
*/
90+
private def checkBacktickPrefix(content: Array[Char], start: Int, end: Int): String =
91+
content.lift(start) match
92+
case Some(char) if char == '`' =>
93+
content.slice(start, end).mkString
94+
case _ =>
95+
""
96+
8197
/**
8298
* Inspect `path` to determine the completion prefix. Only symbols whose name start with the
8399
* returned prefix should be considered.
@@ -92,15 +108,14 @@ object Completion {
92108
completionPrefix(selector :: Nil, pos)
93109
}.getOrElse("")
94110

95-
// We special case Select here because we want to determine if the name
96-
// is an error due to an unclosed backtick.
97-
case (select: untpd.Select) :: _ if (select.name == nme.ERROR) =>
98-
val content = select.source.content()
99-
content.lift(select.nameSpan.start) match
100-
case Some(char) if char == '`' =>
101-
content.slice(select.nameSpan.start, select.span.end).mkString
102-
case _ =>
103-
""
111+
// Foo.`se<TAB> will result in Select(Ident(Foo), <error>)
112+
case (select: untpd.Select) :: _ if select.name == nme.ERROR =>
113+
checkBacktickPrefix(select.source.content(), select.nameSpan.start, select.span.end)
114+
115+
// import scala.util.chaining.`s<TAB> will result in a Ident(<error>)
116+
case (ident: untpd.Ident) :: _ if ident.name == nme.ERROR =>
117+
checkBacktickPrefix(ident.source.content(), ident.span.start, ident.span.end)
118+
104119
case (ref: untpd.RefTree) :: _ =>
105120
if (ref.name == nme.ERROR) ""
106121
else ref.name.toString.take(pos.span.point - ref.span.point)

compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ object JavaParsers {
594594
val vparams = formalParams()
595595
if (!isVoid) rtpt = optArrayBrackets(rtpt)
596596
optThrows()
597-
val bodyOk = !inInterface || mods.isOneOf(Flags.DefaultMethod | Flags.JavaStatic)
597+
val bodyOk = !inInterface || mods.isOneOf(Flags.DefaultMethod | Flags.JavaStatic | Flags.Private)
598598
val body =
599599
if (bodyOk && in.token == LBRACE)
600600
methodBody()

compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import Contexts._
1414
import Decorators._
1515
import DenotTransformers._
1616
import Flags._
17-
import NameKinds.{DefaultGetterName, ModuleClassName}
18-
import NameOps._
17+
import NameKinds.DefaultGetterName
1918
import StdNames._
2019
import Symbols._
2120
import SymUtils._
@@ -560,14 +559,9 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP
560559
case Some(annot) if annot.symbol == jsdefn.JSGlobalAnnot =>
561560
checkJSGlobalLiteral(annot)
562561
val pathName = annot.argumentConstantString(0).getOrElse {
563-
val symTermName = sym.name.exclude(NameKinds.ModuleClassName).toTermName
564-
if (symTermName == nme.apply) {
562+
if ((enclosingOwner is OwnerKind.ScalaMod) && !sym.owner.isPackageObject) {
565563
report.error(
566-
"Native JS definitions named 'apply' must have an explicit name in @JSGlobal",
567-
annot.tree)
568-
} else if (symTermName.isSetterName) {
569-
report.error(
570-
"Native JS definitions with a name ending in '_=' must have an explicit name in @JSGlobal",
564+
"Native JS members inside non-native objects must have an explicit name in @JSGlobal",
571565
annot.tree)
572566
}
573567
sym.defaultJSName
@@ -576,18 +570,6 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP
576570

577571
case Some(annot) if annot.symbol == jsdefn.JSImportAnnot =>
578572
checkJSImportLiteral(annot)
579-
if (annot.arguments.sizeIs < 2) {
580-
val symTermName = sym.name.exclude(NameKinds.ModuleClassName).toTermName
581-
if (symTermName == nme.apply) {
582-
report.error(
583-
"Native JS definitions named 'apply' must have an explicit name in @JSImport",
584-
annot.tree)
585-
} else if (symTermName.isSetterName) {
586-
report.error(
587-
"Native JS definitions with a name ending in '_=' must have an explicit name in @JSImport",
588-
annot.tree)
589-
}
590-
}
591573
annot.argumentConstantString(2).foreach { globalPathName =>
592574
checkGlobalRefPath(globalPathName)
593575
}
@@ -1125,19 +1107,18 @@ object PrepJSInterop {
11251107
*/
11261108
private def checkJSImportLiteral(annot: Annotation)(using Context): Unit = {
11271109
val args = annot.arguments
1128-
val argCount = args.size
1129-
assert(argCount >= 1 && argCount <= 3,
1130-
i"@JSImport annotation $annot does not have between 1 and 3 arguments")
1110+
assert(args.size == 2 || args.size == 3,
1111+
i"@JSImport annotation $annot does not have exactly 2 or 3 arguments")
11311112

11321113
val firstArgIsValid = annot.argumentConstantString(0).isDefined
11331114
if (!firstArgIsValid)
11341115
report.error("The first argument to @JSImport must be a literal string.", args.head)
11351116

1136-
val secondArgIsValid = argCount < 2 || annot.argumentConstantString(1).isDefined || args(1).symbol == jsdefn.JSImportNamespaceModule
1117+
val secondArgIsValid = annot.argumentConstantString(1).isDefined || args(1).symbol == jsdefn.JSImportNamespaceModule
11371118
if (!secondArgIsValid)
11381119
report.error("The second argument to @JSImport must be literal string or the JSImport.Namespace object.", args(1))
11391120

1140-
val thirdArgIsValid = argCount < 3 || annot.argumentConstantString(2).isDefined
1121+
val thirdArgIsValid = args.size < 3 || annot.argumentConstantString(2).isDefined
11411122
if (!thirdArgIsValid)
11421123
report.error("The third argument to @JSImport, when present, must be a literal string.", args(2))
11431124
}

compiler/src/dotty/tools/repl/JLineTerminal.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ final class JLineTerminal extends java.io.Closeable {
152152
// using dummy values, resulting parsed input is probably unused
153153
defaultParsedLine
154154

155+
// In the situation where we have a partial command that we want to
156+
// complete we need to ensure that the :<partial-word> isn't split into
157+
// 2 tokens, but rather the entire thing is treated as the "word", in
158+
// order to insure the : is replaced in the completion.
159+
case ParseContext.COMPLETE if
160+
ParseResult.commands.exists(command => command._1.startsWith(input)) =>
161+
parsedLine(input, cursor)
162+
155163
case ParseContext.COMPLETE =>
156164
// Parse to find completions (typically after a Tab).
157165
def isCompletable(token: Token) = isIdentifier(token) || isKeyword(token)

0 commit comments

Comments
 (0)