@@ -2,33 +2,20 @@ package dotty.tools
22package dotc
33package ast
44
5- import core .*
6- import util .Spans .*
7- import Types .*
8- import Contexts .*
9- import Constants .*
10- import Names .*
11- import NameOps .*
12- import Flags .*
13- import Symbols .*
14- import StdNames .*
15- import Trees .*
16- import ContextOps .*
17- import Decorators .*
18- import transform .SymUtils .*
19- import NameKinds .{DefaultGetterName , EvidenceParamName , UniqueName , WildcardParamName }
20- import typer .{Checking , Namer }
21- import util .{Chars , Property , SourceFile , SourcePosition }
22- import config .Feature .{enabled , migrateTo3 , sourceVersion }
23- import config .SourceVersion .*
24-
5+ import core ._
6+ import util .Spans ._ , Types ._ , Contexts ._ , Constants ._ , Names ._ , NameOps ._ , Flags ._
7+ import Symbols ._ , StdNames ._ , Trees ._ , ContextOps ._
8+ import Decorators ._ , transform .SymUtils ._
9+ import NameKinds .{UniqueName , EvidenceParamName , DefaultGetterName , WildcardParamName }
10+ import typer .{Namer , Checking }
11+ import util .{Property , SourceFile , SourcePosition , Chars }
12+ import config .Feature .{sourceVersion , migrateTo3 , enabled }
13+ import config .SourceVersion ._
2514import collection .mutable .ListBuffer
26- import reporting .*
27-
15+ import reporting ._
2816import annotation .constructorOnly
2917import printing .Formatting .hl
3018import config .Printers
31- import dotty .tools .dotc .core .SymDenotations .NoDenotation
3219
3320import scala .annotation .internal .sharable
3421
@@ -306,51 +293,14 @@ object desugar {
306293 vparam => toDefParam(vparam, keepAnnotations = true , keepDefault = false )
307294 }
308295
309- def ignoreErrorsAndRun [R ](op : => R ): R =
310- val savedState = ctx.typerState.snapshot()
311- val savedReporter = ctx.reporter
312- ctx.typerState.setReporter(Reporter .NoReporter )
313- val ret = op
314- ctx.typerState.setReporter(savedReporter)
315- ctx.typerState.resetTo(savedState)
316- ret
317-
318- // gets arguments should be considered precise
319- val paramPrecises : List [Boolean ] =
320- // indication for the type parameters preciseness
321- val preciseMap : Map [TypeName , Boolean ] = ignoreErrorsAndRun {
322- meth.leadingTypeParams.map(t =>
323- (t.name, t.mods.annotations.exists {a =>
324- try
325- val typedAnnot = ctx.typer.typedExpr(a)
326- if (typedAnnot.denot == NoDenotation ) false
327- else typedAnnot.symbol.owner == defn.PreciseAnnot
328- catch case e : Throwable => false
329- })
330- ).toMap
331- }
332- // mapping type parameters preciseness onto term parameter preciseness
333- meth.termParamss.view.flatten.map(p => p.tpt).map {
334- case Ident (n) => preciseMap.getOrElse(n.asTypeName, false )
335- case _ => false
336- }.toList
337-
338296 def defaultGetters (paramss : List [ParamClause ], n : Int ): List [DefDef ] = paramss match
339297 case ValDefs (vparam :: vparams) :: paramss1 =>
340298 def defaultGetter : DefDef =
341- val (rhs, tpt) =
342- // if the parameter is precise, then we add explicit return type for the
343- // definition to keep the precise type after precise typing.
344- if paramPrecises(n) then
345- val rhsTyped = withMode(Mode .Precise ){ctx.typer.typedExpr(vparam.rhs)}
346- (rhsTyped, TypeTree (rhsTyped.tpe))
347- // otherwise, the desugaring is unchanged from the status quo
348- else (vparam.rhs, TypeTree ())
349299 DefDef (
350300 name = DefaultGetterName (meth.name, n),
351301 paramss = getterParamss(n),
352- tpt = tpt ,
353- rhs = rhs
302+ tpt = TypeTree () ,
303+ rhs = vparam. rhs
354304 )
355305 .withMods(Modifiers (
356306 meth.mods.flags & (AccessFlags | Synthetic ) | (vparam.mods.flags & Inline ),
0 commit comments