Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,21 @@ class Definitions {
val decls = newScope
val arity = name.functionArity
val paramNamePrefix = tpnme.scala_ ++ str.NAME_JOIN ++ name ++ str.EXPAND_SEPARATOR
val argParams =
for (i <- List.range(1, arity + 1)) yield
enterTypeParam(cls, paramNamePrefix ++ "T" ++ i.toString, Contravariant, decls)
val argParams = List.tabulate(arity) { i =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to argParamRefs?

enterTypeParam(cls, paramNamePrefix ++ "T" ++ (i + 1).toString, Contravariant, decls).typeRef
}
val resParam = enterTypeParam(cls, paramNamePrefix ++ "R", Covariant, decls)
val (methodType, parentTraits) =
if (name.firstPart.startsWith(str.ImplicitFunction)) {
val superTrait =
FunctionType(arity).appliedTo(argParams.map(_.typeRef) ::: resParam.typeRef :: Nil)
FunctionType(arity).appliedTo(argParams ::: resParam.typeRef :: Nil)
(ImplicitMethodType, superTrait :: Nil)
}
else (MethodType, Nil)
val applyMeth =
decls.enter(
newMethod(cls, nme.apply,
methodType(argParams.map(_.typeRef), resParam.typeRef), Deferred))
methodType(argParams, resParam.typeRef), Deferred))
denot.info =
ClassInfo(ScalaPackageClass.thisType, cls, ObjectType :: parentTraits, decls)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
val MethodTpe(_, formals, restpe) = meth.info
(formals, restpe)
case _ =>
(List.range(0, defaultArity) map alwaysWildcardType, WildcardType)
(List.tabulate(defaultArity)(alwaysWildcardType), WildcardType)
}

def typedFunction(tree: untpd.Function, pt: Type)(implicit ctx: Context) = track("typedFunction") {
Expand Down
11 changes: 6 additions & 5 deletions compiler/src/dotty/tools/dotc/util/SourcePosition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ extends interfaces.SourcePosition {
source.content.slice(source.startOfLine(start), source.nextLine(end))

/** The lines of the position */
def lines: List[Int] =
List.range(source.offsetToLine(start), source.offsetToLine(end + 1)) match {
case Nil => line :: Nil
case xs => xs
}
def lines: List[Int] = {
val startOffset = source.offsetToLine(start)
val endOffset = source.offsetToLine(end + 1)
if (startOffset >= endOffset) line :: Nil
else List.tabulate(endOffset - startOffset)(i => i + startOffset)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the offset to add it back is confusing, I would just keep the original code here since it shouldn't be performance-sensitive, or do (startOffset to endOffset).toList maybe.

}

def lineOffsets: List[Int] =
lines.map(source.lineToOffset(_))
Expand Down