Skip to content
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

Add reflect TypeRepr.substituteTypes #13166

Merged
merged 1 commit into from Oct 22, 2021

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@cchantep
Copy link
Member

cchantep commented Aug 2, 2021

Interesting, thanks ... is there a snapshot build?

@nicolasstucki nicolasstucki self-assigned this Aug 3, 2021
@cchantep
Copy link
Member

Up ?

@cchantep
Copy link
Member

That's seems ok for me:

It would be nice to merge it, to remove this blocker.

@nicolasstucki
Copy link
Contributor Author

I still need some tests for this feature. @cchantep could you help me create a small self contained example that captures your use case?

@cchantep
Copy link
Member

@nicolasstucki I don't see how to directly update the existing test (BTW I think it lakes a proper documentation).

  inline def testSubst: Unit = ${ testSubstImpl }

  def testSubstImpl(using q: Quotes): Expr[Unit] = {
    import q.reflect.*

    val intTpe = TypeRepr.of[Int]
    val strOptTpe = TypeRepr.of[Option[String]]

    val tpeArgs: List[TypeRepr] = strOptTpe match {
      case AppliedType(_, args) => args
      case _                    => List.empty[TypeRepr]
    }
    
    val intOptTpe = strOptTpe.substituteTypes(
      tpeArgs.map(_.typeSymbol), List(intTpe))

    val repr = s"${strOptTpe.show} to ${intOptTpe.show}"

    '{
      println(${Expr(repr)})
    }
  }

Expected printed result:

scala.Option[scala.Predef.String] to scala.Option[scala.Int]

@cchantep
Copy link
Member

Flaky unrelated tests ?

@nicolasstucki
Copy link
Contributor Author

Flaky unrelated tests ?

No, a tab auto-complete test that changed

@nicolasstucki nicolasstucki marked this pull request as ready for review October 22, 2021 09:04
@cchantep
Copy link
Member

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants