Skip to content

Properly desugar inline given .. with .. #14284

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 5 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ object desugar {
DefDef(
className.toTermName, joinParams(constrTparams, defParamss),
classTypeRef, creatorExpr)
.withMods(companionMods | mods.flags.toTermFlags & GivenOrImplicit | Final)
.withMods(companionMods | mods.flags.toTermFlags & (GivenOrImplicit | Inline) | Final)
.withSpan(cdef.span) :: Nil
}

Expand All @@ -809,7 +809,7 @@ object desugar {
Nil
}
}
val classMods = if mods.is(Given) then mods | Synthetic else mods
val classMods = if mods.is(Given) then mods &~ Inline | Synthetic else mods
cpy.TypeDef(cdef: TypeDef)(
name = className,
rhs = cpy.Template(impl)(constr, parents1, clsDerived, self1,
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3626,7 +3626,7 @@ object Parsers {
val templ =
if isStatSep || isStatSeqEnd then Template(constr, parents, Nil, EmptyValDef, Nil)
else withTemplate(constr, parents)
if noParams then ModuleDef(name, templ)
if noParams && !mods.is(Inline) then ModuleDef(name, templ)
else TypeDef(name.toTypeName, templ)
end gdef
finalizeDef(gdef, mods1, start)
Expand Down
6 changes: 6 additions & 0 deletions tests/neg/i14177a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.compiletime.*

trait C[A]

inline given [Tup <: Tuple]: C[Tup] with
val cs = summonAll[Tuple.Map[Tup, C]] // error cannot reduce inline match with
15 changes: 15 additions & 0 deletions tests/pos/i14177b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class T

inline given fail1: T with
Copy link
Member

@smarter smarter Jan 17, 2022

Choose a reason for hiding this comment

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

Does transparent inline work / do anything useful here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes sure that we do not hit the previous issue where the summonAll was not inlined due to the inline flag that was kept by mistake on the class fail1.

Copy link
Member

@smarter smarter Jan 18, 2022

Choose a reason for hiding this comment

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

I mean, there are no testcases with transparent in this pr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I completely missed the transparent. I will add some test cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Transparent is failing for the wrong reason. I do not see how transparent would be useful here because we already have the precise type. I will disallow this combination and make sure the error message is correct.

val cs = scala.compiletime.summonAll[EmptyTuple]
inline given fail2[X]: T with
val cs = scala.compiletime.summonAll[EmptyTuple]
inline given fail3(using DummyImplicit): T with
val cs = scala.compiletime.summonAll[EmptyTuple]

inline given ok1: T = new T:
val cs = scala.compiletime.summonAll[EmptyTuple]
inline given ok2[X]: T = new T:
val cs = scala.compiletime.summonAll[EmptyTuple]
inline given ok3(using DummyImplicit): T = new T:
val cs = scala.compiletime.summonAll[EmptyTuple]
13 changes: 13 additions & 0 deletions tests/pos/i14282.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
trait Foo[A] {
inline def foo(): Unit
}

inline given FooA[A]: Foo[A] with {
inline def foo(): Unit = println()
}
def test1 = FooA.foo()

inline given FooInt: Foo[Int] with {
inline def foo(): Unit = println()
}
def test2 = FooInt.foo()