Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6186261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:51:20+00:00 2026-05-24T01:51:20+00:00

Why does this Scala code fail to typecheck? trait T { type A }

  • 0

Why does this Scala code fail to typecheck?

trait T { type A }
trait GenFoo[A0, S <: T { type A = A0 }]
trait Foo[S <: T] extends GenFoo[S#A, S]

I don’t understand why “type arguments [S#A,S] do not conform to trait GenFoo’s type parameter bounds [A0,S <: T{type A = A0}]”. Is there a work-around?

Edit: As has been pointed out, the conformance error stems from the failure to verify S <: T{type A = S#A}. Daniel Sobral pointed to -explaintypes, which tells us:

S <: T{type A = S#A}?
  S <: T?
  true
  S specializes type A?
    this.A = this.A?
      S = this.type?
      false
    false
  false
false

I’m not sure how to interpret this.

Note that we get an illegal cyclic reference if we try to define,

trait Foo[S <: T { type A = S#A } ] extends GenFoo[S#A, S]

although the type refinement here doesn’t seem to add any new information. (See also Why is this cyclic reference with a type projection illegal?)

My motivation is to create a trait Foo[S <: T] that specializes on S#A, as in: How to specialize on a type projection in Scala? To get this to work, I’m trying to surface S#A as an explicit parameter A0 in the implementation trait GenFoo, which can be specialized directly. I was hoping to apply the type refinement idea from Miles Sabin’s answer to Why is this cyclic reference with a type projection illegal? but I run into this conformance error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:51:22+00:00Added an answer on May 24, 2026 at 1:51 am

    This seems to be the answer:

    S specializes type A?

    The question about specialize comes from here: T { type A = A0 }. This is the type T with type A specialized — meaning, it is more restricted than the original T.

    The answer to that question is no — there’s no constrains on S that it be specialized.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why does this code fail to display the category name Apples using the current
I have the following Scala code. import scala.actors.Actor object Alice extends Actor { this.start
What does this mean exactly? I'm doing something like this: File.Copy(@\\foo\bar\baz.txt, @c:\test\baz.txt); MSDN doesn't
Why does this lambda expression not compile? Action a = () => throw new
Why does this code: class A { public: explicit A(int x) {} }; class
The code currently does this and the fgetpos does handle files larger than 4GB
I am not able to understand the point of Option[T] class in Scala. I
I have some Scala code that does something nifty with two different versions of
I'm running this scala code on a 32-bit quad-core Core2 system: def job(i:Int,s:Int):Long =
When I'm writing this code, I've got a Compile error in Scala var s:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.