@@ -35,7 +35,6 @@ import config.SourceVersion.*
3535import  config .SourceVersion 
3636import  dotty .tools .dotc .config .MigrationVersion 
3737import  dotty .tools .dotc .util .chaining .* 
38- import  dotty .tools .dotc .config .Printers .variances 
3938
4039object  Parsers  {
4140
@@ -2288,49 +2287,28 @@ object Parsers {
22882287     *  TypeBound  ::= Type 
22892288     *               | CaptureSet -- under captureChecking 
22902289     */  
2291-     def  typeBounds (isCapParamOrMem : Boolean  =  false ):  TypeBoundsTree  = 
2292-       def  isCapsBound (t : Tree ):  Boolean  = 
2293-         t match 
2294-           case  Select (qual, tpnme.CapSet ) =>  true 
2295-           case  Annotated (Select (qual, tpnme.CapSet ), _) =>  true 
2296-           case  _ =>  false 
2297- 
2290+     def  typeBounds ():  TypeBoundsTree  = 
22982291      atSpan(in.offset): 
2299-         var  lbound  =  bound(SUPERTYPE , isCapParamOrMem)
2300-         var  ubound  =  bound(SUBTYPE , isCapParamOrMem)
2301-         if  Feature .ccEnabled &&  ! isCapParamOrMem then 
2302-           /*  We haven't annotated the `^` to a type parameter/member,
2303-              but an explicit capture-set bound makes it a capture parameter, so we make sure 
2304-              to add the missing other CapSet bound. */  
2305-           if  lbound.isEmpty &&  isCapsBound(ubound) then 
2306-             lbound =  capsBound(Nil , isLowerBound =  true )
2307-           if  ubound.isEmpty &&  isCapsBound(lbound) then 
2308-             ubound =  capsBound(Nil , isLowerBound =  false )
2309-         end if 
2310-         TypeBoundsTree (lbound, ubound)
2311-     end  typeBounds 
2312- 
2313-     private  def  bound (tok : Int , isCapParamOrMem : Boolean  =  false ):  Tree  = 
2292+         TypeBoundsTree (bound(SUPERTYPE ), bound(SUBTYPE ))
2293+ 
2294+     private  def  bound (tok : Int ):  Tree  = 
23142295      if  (in.token ==  tok) then 
23152296        in.nextToken()
23162297        if  Feature .ccEnabled &&  (in.token ==  LBRACE  &&  ! isDclIntroNext) then 
23172298          capsBound(captureSet(), isLowerBound =  tok ==  SUPERTYPE )
23182299        else  toplevelTyp()
2319-       else  if  Feature .ccEnabled &&  isCapParamOrMem then 
2320-         //  we hit this case if we have annotated a post-fix `^` but no bounds to a type parameter/member
2321-         capsBound(Nil , isLowerBound =  tok ==  SUPERTYPE )
23222300      else  EmptyTree 
23232301
23242302    private  def  capsBound (refs : List [Tree ], isLowerBound : Boolean  =  false ):  Tree  = 
23252303      if  isLowerBound &&  refs.isEmpty then  //  lower bounds with empty capture sets become a pure CapSet
23262304        Select (scalaDot(nme.caps), tpnme.CapSet )
23272305      else 
2328-         makeRetaining(Select (scalaDot(nme.caps), tpnme.CapSet ), refs, if  refs.isEmpty  then  tpnme.retainsCap  else   tpnme.retains)
2306+         makeRetaining(Select (scalaDot(nme.caps), tpnme.CapSet ), refs, tpnme.retains)
23292307
23302308    /**  TypeAndCtxBounds  ::=  TypeBounds [`:` ContextBounds] 
23312309     */  
2332-     def  typeAndCtxBounds (pname : TypeName ,  isCapParamOrMem :  Boolean   =   false ):  Tree  =  {
2333-       val  t  =  typeBounds(isCapParamOrMem )
2310+     def  typeAndCtxBounds (pname : TypeName ):  Tree  =  {
2311+       val  t  =  typeBounds()
23342312      val  cbs  =  contextBounds(pname)
23352313      if  (cbs.isEmpty) t
23362314      else  atSpan((t.span union cbs.head.span).start) { ContextBounds (t, cbs) }
@@ -3580,16 +3558,23 @@ object Parsers {
35803558              WildcardParamName .fresh().toTypeName
35813559            else  ident().toTypeName
35823560          val  isCap  =  gobbleHat()
3583-           if  isCap &&  mods.isOneOf(Covariant  |  Contravariant ) then 
3584-             syntaxError(em " capture parameters cannot have `+/-` variance annotations " ) //  TODO we might want to allow those
3585-           if  isCap &&  in.token ==  LBRACKET  then 
3586-             syntaxError(em " capture parameters do not take type parameters " )
3587-             in.nextToken()
3561+           if  isCap then 
3562+             if  mods.isOneOf(Covariant  |  Contravariant ) then 
3563+               syntaxError(em " capture parameters cannot have `+/-` variance annotations " ) //  TODO we might want to allow those
3564+             if  in.token ==  LBRACKET  then 
3565+               syntaxError(em " capture parameters do not take type parameters " )
3566+               in.nextToken()
3567+           end if 
35883568          val  hkparams  =  typeParamClauseOpt(ParamOwner .Hk )
35893569          val  bounds  = 
3590-             if  paramOwner.acceptsCtxBounds then  typeAndCtxBounds(name, isCap)
3591-             else  if  sourceVersion.enablesNewGivens &&  paramOwner ==  ParamOwner .Type  then  typeAndCtxBounds(name, isCap)
3592-             else  typeBounds(isCap)
3570+             if  ! isCap &&  paramOwner.acceptsCtxBounds then  typeAndCtxBounds(name)
3571+             else  if  ! isCap &&  sourceVersion.enablesNewGivens &&  paramOwner ==  ParamOwner .Type  then  typeAndCtxBounds(name)
3572+             else  typeBounds()
3573+           if  isCap then 
3574+             bounds.pushAttachment(CaptureVar , ())
3575+             val  t  =  contextBounds(name)
3576+             if  t.nonEmpty then 
3577+               syntaxError(em " capture parameters cannot have context bounds " , t.head.span)
35933578          TypeDef (name, lambdaAbstract(hkparams, bounds)).withMods(mods)
35943579        }
35953580      }
@@ -4135,8 +4120,11 @@ object Parsers {
41354120        def  makeTypeDef (rhs : Tree ):  Tree  =  {
41364121          val  rhs1  =  lambdaAbstractAll(tparams ::  vparamss, rhs)
41374122          val  tdef  =  TypeDef (nameIdent.name.toTypeName, rhs1)
4138-           if  ( nameIdent.isBackquoted) 
4123+           if  nameIdent.isBackquoted  then 
41394124            tdef.pushAttachment(Backquoted , ())
4125+           if  isCapDef then  rhs.match 
4126+             case  ContextBounds (_, _) =>  syntaxError(em " capture-set member declarations cannot have context bounds " , rhs.span)
4127+             case  rhs =>  rhs.pushAttachment(CaptureVar , ())
41404128          finalizeDef(tdef, mods, start)
41414129        }
41424130
@@ -4145,7 +4133,7 @@ object Parsers {
41454133            in.nextToken()
41464134            makeTypeDef(typeDefRHS())
41474135          case  SUBTYPE  |  SUPERTYPE  => 
4148-             typeAndCtxBounds(tname, isCapDef ) match 
4136+             typeAndCtxBounds(tname) match 
41494137              case  bounds : TypeBoundsTree  if  in.token ==  EQUALS  => 
41504138                val  eqOffset  =  in.skipToken()
41514139                var  rhs  =  typeDefRHS()
@@ -4166,10 +4154,10 @@ object Parsers {
41664154                makeTypeDef(rhs)
41674155              case  bounds =>  makeTypeDef(bounds)
41684156          case  SEMI  |  NEWLINE  |  NEWLINES  |  COMMA  |  RBRACE  |  OUTDENT  |  EOF  => 
4169-             makeTypeDef(typeAndCtxBounds(tname, isCapDef ))
4157+             makeTypeDef(typeAndCtxBounds(tname))
41704158          case  _ if  (staged &  StageKind .QuotedPattern ) !=  0 
41714159              ||  sourceVersion.enablesNewGivens &&  in.isColon => 
4172-             makeTypeDef(typeAndCtxBounds(tname, isCapDef ))
4160+             makeTypeDef(typeAndCtxBounds(tname))
41734161          case  _ => 
41744162            syntaxErrorOrIncomplete(ExpectedTypeBoundOrEquals (in.token))
41754163            return  EmptyTree  //  return to avoid setting the span to EmptyTree
0 commit comments