Extension of Inner Classes #17650
                  
                    
                      ftucky
                    
                  
                
                  started this conversation in
                Feature Requests
              
            Replies: 0 comments
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
Scala Version
3.2.2
Minimized Code
Result
Compilation fails with
value next is not a member of A#X.Expectation
Would be elegant to let code compile.
For an inner projection
P#T,(x:P#T).extensionMethod(args)would desugar into something similar to{ val outer : P = x.$outer outer.extensionMethod(inner:outer.T)(args) }Rationale
In a pattern where the inner class is final but the outer class is open, it is elegant to create extensions which only make sense on the subclasses of the outer class.
So that
bx:B#Xs have afoomethod, whileax:A#Xs do not.Today, a significant boiler plate is necessary:
deflectmethod is present in the innerclass, and must be left public.Beta Was this translation helpful? Give feedback.
All reactions