Skip to content

Fix #6395: Drop expected type in inlineCall #6459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ object SymDenotations {
// need to use initial owner to disambiguate, as multiple private symbols with the same name
// might have been moved from different origins into the same class

/** The name with which the denoting symbol was created */
/** The effective name with which the denoting symbol was created */
final def originalName(implicit ctx: Context): Name = initial.effectiveName

/** The owner with which the denoting symbol was created. */
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ object Inliner {
* @return An `Inlined` node that refers to the original call and the inlined bindings
* and body that replace it.
*/
def inlineCall(tree: Tree, pt: Type)(implicit ctx: Context): Tree = {
def inlineCall(tree: Tree)(implicit ctx: Context): Tree = {

/** Set the position of all trees logically contained in the expansion of
* inlined call `call` to the position of `call`. This transform is necessary
Expand Down Expand Up @@ -102,11 +102,11 @@ object Inliner {

val tree1 = liftBindings(tree, identity)
if (bindings.nonEmpty)
cpy.Block(tree)(bindings.toList, inlineCall(tree1, pt))
cpy.Block(tree)(bindings.toList, inlineCall(tree1))
else if (enclosingInlineds.length < ctx.settings.XmaxInlines.value) {
val body = bodyToInline(tree.symbol) // can typecheck the tree and thereby produce errors
if (ctx.reporter.hasErrors) tree
else new Inliner(tree, body).inlined(pt, tree.sourcePos)
else new Inliner(tree, body).inlined(tree.sourcePos)
}
else
errorTree(
Expand Down Expand Up @@ -384,7 +384,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
}

/** The Inlined node representing the inlined call */
def inlined(pt: Type, sourcePos: SourcePosition): Tree = {
def inlined(sourcePos: SourcePosition): Tree = {

if (callTypeArgs.length == 1)
if (inlinedMethod == defn.Compiletime_constValue) {
Expand Down Expand Up @@ -509,7 +509,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
}

// Run a typing pass over the inlined tree. See InlineTyper for details.
val expansion1 = inlineTyper.typed(expansion, pt)(inlineCtx)
val expansion1 = inlineTyper.typed(expansion)(inlineCtx)

if (ctx.settings.verbose.value) {
inlining.println(i"to inline = $rhsToInline")
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2772,7 +2772,7 @@ class Typer extends Namer
!ctx.isAfterTyper &&
!ctx.reporter.hasErrors) {
tree.tpe <:< wildApprox(pt)
readaptSimplified(Inliner.inlineCall(tree, pt))
readaptSimplified(Inliner.inlineCall(tree))
}
else if (tree.symbol.isScala2Macro) {
if (ctx.settings.XignoreScala2Macros.value) {
Expand All @@ -2786,7 +2786,7 @@ class Typer extends Namer
// As the macro is implemented in the bootstrapped library, it can only be used from the bootstrapped compiler.
val Apply(TypeApply(Select(sc, _), _), args) = tree
val newCall = ref(defn.InternalStringContextModule_f).appliedTo(sc).appliedToArgs(args)
Inliner.inlineCall(newCall, pt)
readaptSimplified(Inliner.inlineCall(newCall))
} else {
ctx.error("Scala 2 macro cannot be used in Dotty. See http://dotty.epfl.ch/docs/reference/dropped-features/macros.html", tree.sourcePos)
tree
Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i6395.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Foo {
inline def (self: Int) foo (that: Int): Int = 5
def (self: Int) bar: Int = self
1.foo(2).bar
}