diff options
-rw-r--r-- | build.xml | 7 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/html/page/Template.scala | 139 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/interactive/Global.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 22 | ||||
-rwxr-xr-x | src/library/scala/collection/LinearSeqOptimized.scala | 18 | ||||
-rw-r--r-- | src/library/scala/collection/SeqLike.scala | 16 | ||||
-rw-r--r-- | test/files/neg/t6788.check | 5 | ||||
-rw-r--r-- | test/files/neg/t6788.scala | 7 | ||||
-rw-r--r-- | test/files/neg/t6829.check | 36 | ||||
-rw-r--r-- | test/files/neg/t6829.scala | 64 | ||||
-rw-r--r-- | test/files/pos/classtag-pos.flags | 1 | ||||
-rw-r--r-- | test/files/pos/classtag-pos.scala | 5 | ||||
-rw-r--r-- | test/files/run/streams.check | 14 | ||||
-rw-r--r-- | test/files/run/streams.scala | 20 | ||||
-rw-r--r-- | test/files/run/t2544.check | 4 | ||||
-rw-r--r-- | test/files/run/t2544.scala | 22 |
17 files changed, 283 insertions, 104 deletions
@@ -2719,7 +2719,12 @@ DISTRIBUTION <target name="dist.base" depends="dist.start"> <mkdir dir="${dist.dir}/lib"/> <copy toDir="${dist.dir}/lib"> - <fileset dir="${build-pack.dir}/lib"/> + <fileset dir="${build-pack.dir}/lib"> + <include name="jline.jar"/> + <include name="scalacheck.jar"/> + <include name="scala-partest.jar"/> + <include name="scalap.jar"/> + </fileset> </copy> <mkdir dir="${dist.dir}/bin"/> <!-- TODO - Stop being inefficient and don't copy OSGi bundles overtop other jars. --> diff --git a/src/compiler/scala/tools/nsc/doc/html/page/Template.scala b/src/compiler/scala/tools/nsc/doc/html/page/Template.scala index e885e9c56e..ea07ff29c4 100644 --- a/src/compiler/scala/tools/nsc/doc/html/page/Template.scala +++ b/src/compiler/scala/tools/nsc/doc/html/page/Template.scala @@ -335,12 +335,10 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp } } - def memberToShortCommentHtml(mbr: MemberEntity, isSelf: Boolean): NodeSeq = { - if (mbr.comment.isEmpty) - NodeSeq.Empty - else - <p class="shortcomment cmt">{ memberToUseCaseCommentHtml(mbr, isSelf) }{ inlineToHtml(mbr.comment.get.short) }</p> - } + def memberToShortCommentHtml(mbr: MemberEntity, isSelf: Boolean): NodeSeq = + mbr.comment.fold(NodeSeq.Empty) { comment => + <p class="shortcomment cmt">{ memberToUseCaseCommentHtml(mbr, isSelf) }{ inlineToHtml(comment.short) }</p> + } def memberToInlineCommentHtml(mbr: MemberEntity, isSelf: Boolean): NodeSeq = <p class="comment cmt">{ inlineToHtml(mbr.comment.get.short) }</p> @@ -361,37 +359,34 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp case _ => Nil } - def mbrCmt = mbr.comment.get - - def paramCommentToHtml(prs: List[ParameterEntity]): NodeSeq = prs match { + def paramCommentToHtml(prs: List[ParameterEntity], comment: Comment): NodeSeq = prs match { case (tp: TypeParam) :: rest => val paramEntry: NodeSeq = { - <dt class="tparam">{ tp.name }</dt><dd class="cmt">{ bodyToHtml(mbrCmt.typeParams(tp.name)) }</dd> + <dt class="tparam">{ tp.name }</dt><dd class="cmt">{ bodyToHtml(comment.typeParams(tp.name)) }</dd> } - paramEntry ++ paramCommentToHtml(rest) + paramEntry ++ paramCommentToHtml(rest, comment) case (vp: ValueParam) :: rest => val paramEntry: NodeSeq = { - <dt class="param">{ vp.name }</dt><dd class="cmt">{ bodyToHtml(mbrCmt.valueParams(vp.name)) }</dd> + <dt class="param">{ vp.name }</dt><dd class="cmt">{ bodyToHtml(comment.valueParams(vp.name)) }</dd> } - paramEntry ++ paramCommentToHtml(rest) + paramEntry ++ paramCommentToHtml(rest, comment) case _ => NodeSeq.Empty } - if (mbr.comment.isEmpty) NodeSeq.Empty - else { + mbr.comment.fold(NodeSeq.Empty) { comment => val cmtedPrs = prs filter { - case tp: TypeParam => mbrCmt.typeParams isDefinedAt tp.name - case vp: ValueParam => mbrCmt.valueParams isDefinedAt vp.name + case tp: TypeParam => comment.typeParams isDefinedAt tp.name + case vp: ValueParam => comment.valueParams isDefinedAt vp.name } - if (cmtedPrs.isEmpty && mbrCmt.result.isEmpty) NodeSeq.Empty + if (cmtedPrs.isEmpty && comment.result.isEmpty) NodeSeq.Empty else { <dl class="paramcmts block">{ - paramCommentToHtml(cmtedPrs) ++ ( - mbrCmt.result match { + paramCommentToHtml(cmtedPrs, comment) ++ ( + comment.result match { case None => NodeSeq.Empty case Some(cmt) => <dt>returns</dt><dd class="cmt">{ bodyToHtml(cmt) }</dd> @@ -470,7 +465,7 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp } // --- start attributes block vals - val attributes: Seq[scala.xml.Node] = { + val attributes: NodeSeq = { val fvs: List[comment.Paragraph] = visibility(mbr).toList if (fvs.isEmpty || isReduced) NodeSeq.Empty else { @@ -479,7 +474,7 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp } } - val definitionClasses: Seq[scala.xml.Node] = { + val definitionClasses: NodeSeq = { val inDefTpls = mbr.inDefinitionTemplates if ((inDefTpls.tail.isEmpty && (inDefTpls.head == inTpl)) || isReduced) NodeSeq.Empty else { @@ -488,7 +483,7 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp } } - val fullSignature: Seq[scala.xml.Node] = { + val fullSignature: NodeSeq = { mbr match { case nte: NonTemplateMemberEntity if nte.isUseCase => <div class="full-signature-block toggleContainer"> @@ -499,14 +494,14 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp } } - val selfType: Seq[scala.xml.Node] = mbr match { + val selfType: NodeSeq = mbr match { case dtpl: DocTemplateEntity if (isSelf && !dtpl.selfType.isEmpty && !isReduced) => <dt>Self Type</dt> <dd>{ typeToHtml(dtpl.selfType.get, hasLinks = true) }</dd> case _ => NodeSeq.Empty } - val annotations: Seq[scala.xml.Node] = { + val annotations: NodeSeq = { // A list of annotations which don't show their arguments, e. g. because they are shown separately. val annotationsWithHiddenArguments = List("deprecated", "Deprecated", "migration") @@ -528,7 +523,7 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp } else NodeSeq.Empty } - val sourceLink: Seq[scala.xml.Node] = mbr match { + val sourceLink: NodeSeq = mbr match { case dtpl: DocTemplateEntity if (isSelf && dtpl.sourceUrl.isDefined && dtpl.inSource.isDefined && !isReduced) => val (absFile, line) = dtpl.inSource.get <dt>Source</dt> @@ -536,83 +531,87 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp case _ => NodeSeq.Empty } - val deprecation: Seq[scala.xml.Node] = - if (mbr.deprecation.isEmpty || isReduced) NodeSeq.Empty - else { - <dt>Deprecated</dt> - <dd class="cmt">{ bodyToHtml(mbr.deprecation.get) }</dd> + val deprecation: NodeSeq = + mbr.deprecation match { + case Some(deprecation) if !isReduced => + <dt>Deprecated</dt> + <dd class="cmt">{ bodyToHtml(deprecation) }</dd> + case _ => NodeSeq.Empty } - val migration: Seq[scala.xml.Node] = - if(mbr.migration.isEmpty || isReduced) NodeSeq.Empty - else { + val migration: NodeSeq = + mbr.migration match { + case Some(migration) if !isReduced => <dt>Migration</dt> - <dd class="cmt">{ bodyToHtml(mbr.migration.get) }</dd> + <dd class="cmt">{ bodyToHtml(migration) }</dd> + case _ => NodeSeq.Empty } - val mainComment: Seq[scala.xml.Node] = mbr.comment match { + val mainComment: NodeSeq = mbr.comment match { case Some(comment) if (! isReduced) => + def orEmpty[T](it: Iterable[T])(gen: =>NodeSeq): NodeSeq = + if (it.isEmpty) NodeSeq.Empty else gen + val example = - if(!comment.example.isEmpty) + orEmpty(comment.example) { <div class="block">Example{ if (comment.example.length > 1) "s" else ""}: - <ol>{ - val exampleXml: List[scala.xml.NodeSeq] = - for(example <- comment.example ) yield - <li class="cmt">{ bodyToHtml(example) }</li> - exampleXml.reduceLeft(_ ++ Text(", ") ++ _) + <ol>{ + val exampleXml: List[NodeSeq] = for (ex <- comment.example) yield + <li class="cmt">{ bodyToHtml(ex) }</li> + exampleXml.reduceLeft(_ ++ Text(", ") ++ _) }</ol> - </div> - else NodeSeq.Empty + </div> + } - val version: Seq[scala.xml.Node] = - if(!comment.version.isEmpty) { + val version: NodeSeq = + orEmpty(comment.version) { <dt>Version</dt> - <dd>{ for(body <- comment.version.toList) yield {bodyToHtml(body)} }</dd> - } else NodeSeq.Empty + <dd>{ for(body <- comment.version.toList) yield bodyToHtml(body) }</dd> + } - val sinceVersion: Seq[scala.xml.Node] = - if(!comment.since.isEmpty) { + val sinceVersion: NodeSeq = + orEmpty(comment.since) { <dt>Since</dt> - <dd>{ for(body <- comment.since.toList) yield {bodyToHtml(body)} }</dd> - } else NodeSeq.Empty + <dd>{ for(body <- comment.since.toList) yield bodyToHtml(body) }</dd> + } - val note: Seq[scala.xml.Node] = - if(!comment.note.isEmpty) { + val note: NodeSeq = + orEmpty(comment.note) { <dt>Note</dt> <dd>{ - val noteXml: List[scala.xml.NodeSeq] = (for(note <- comment.note ) yield <span class="cmt">{bodyToHtml(note)}</span> ) + val noteXml: List[NodeSeq] = for(note <- comment.note ) yield <span class="cmt">{bodyToHtml(note)}</span> noteXml.reduceLeft(_ ++ Text(", ") ++ _) }</dd> - } else NodeSeq.Empty + } - val seeAlso: Seq[scala.xml.Node] = - if(!comment.see.isEmpty) { + val seeAlso: NodeSeq = + orEmpty(comment.see) { <dt>See also</dt> <dd>{ - val seeXml:List[scala.xml.NodeSeq]=(for(see <- comment.see ) yield <span class="cmt">{bodyToHtml(see)}</span> ) + val seeXml: List[NodeSeq] = for(see <- comment.see ) yield <span class="cmt">{bodyToHtml(see)}</span> seeXml.reduceLeft(_ ++ _) }</dd> - } else NodeSeq.Empty + } - val exceptions: Seq[scala.xml.Node] = - if(!comment.throws.isEmpty) { + val exceptions: NodeSeq = + orEmpty(comment.throws) { <dt>Exceptions thrown</dt> <dd>{ - val exceptionsXml: Iterable[scala.xml.NodeSeq] = - for(exception <- comment.throws.toList.sortBy(_._1) ) yield - <span class="cmt">{Text(exception._1) ++ bodyToHtml(exception._2)}</span> + val exceptionsXml: List[NodeSeq] = + for((name, body) <- comment.throws.toList.sortBy(_._1) ) yield + <span class="cmt">{Text(name) ++ bodyToHtml(body)}</span> exceptionsXml.reduceLeft(_ ++ Text("") ++ _) }</dd> - } else NodeSeq.Empty + } - val todo: Seq[scala.xml.Node] = - if(!comment.todo.isEmpty) { + val todo: NodeSeq = + orEmpty(comment.todo) { <dt>To do</dt> <dd>{ - val todoXml: List[scala.xml.NodeSeq] = (for(todo <- comment.todo ) yield <span class="cmt">{bodyToHtml(todo)}</span> ) + val todoXml: List[NodeSeq] = (for(todo <- comment.todo ) yield <span class="cmt">{bodyToHtml(todo)}</span> ) todoXml.reduceLeft(_ ++ Text(", ") ++ _) }</dd> - } else NodeSeq.Empty + } example ++ version ++ sinceVersion ++ exceptions ++ todo ++ note ++ seeAlso diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala index 0fc4fcaaf7..4ab7b98b3d 100644 --- a/src/compiler/scala/tools/nsc/interactive/Global.scala +++ b/src/compiler/scala/tools/nsc/interactive/Global.scala @@ -56,7 +56,6 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") import log.logreplay debugLog("logger: " + log.getClass + " writing to " + (new java.io.File(logName)).getAbsolutePath) debugLog("classpath: "+classPath) - Console.err.println("\n ======= CHECK THREAD ACCESS compiler build ========\n") private var curTime = System.nanoTime private def timeStep = { diff --git a/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala b/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala index 6abb52a649..60399f53bf 100644 --- a/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala +++ b/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala @@ -212,7 +212,11 @@ trait TypeStrings { } private def tparamString[T: ru.TypeTag] : String = { - def typeArguments: List[ru.Type] = ru.typeOf[T] match { case ru.TypeRef(_, _, args) => args; case _ => Nil } + def typeArguments: List[ru.Type] = { + import ru.TypeRefTag // otherwise the pattern match will be unchecked + // because TypeRef is an abstract type + ru.typeOf[T] match { case ru.TypeRef(_, _, args) => args; case _ => Nil } + } // [Eugene to Paul] need to use not the `rootMirror`, but a mirror with the REPL's classloader // how do I get to it? acquiring context classloader seems unreliable because of multithreading def typeVariables: List[java.lang.Class[_]] = typeArguments map (targ => ru.rootMirror.runtimeClass(targ)) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index f8adcaa25b..9d390476db 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3497,12 +3497,13 @@ trait Typers extends Modes with Adaptations with Tags { // println(util.Position.formatMessage(uncheckedPattern.pos, "made unchecked type test into a checked one", true)) val args = List(uncheckedPattern) + val app = atPos(uncheckedPattern.pos)(Apply(classTagExtractor, args)) // must call doTypedUnapply directly, as otherwise we get undesirable rewrites // and re-typechecks of the target of the unapply call in PATTERNmode, // this breaks down when the classTagExtractor (which defineds the unapply member) is not a simple reference to an object, // but an arbitrary tree as is the case here - doTypedUnapply(Apply(classTagExtractor, args), classTagExtractor, classTagExtractor, args, PATTERNmode, pt) - } + doTypedUnapply(app, classTagExtractor, classTagExtractor, args, PATTERNmode, pt) + } // if there's a ClassTag that allows us to turn the unchecked type test for `pt` into a checked type test // return the corresponding extractor (an instance of ClassTag[`pt`]) @@ -4646,12 +4647,11 @@ trait Typers extends Modes with Adaptations with Tags { // [Eugene] no more MaxArrayDims. ClassTags are flexible enough to allow creation of arrays of arbitrary dimensionality (w.r.t JVM restrictions) val Some((level, componentType)) = erasure.GenericArray.unapply(tpt.tpe) val tagType = List.iterate(componentType, level)(tpe => appliedType(ArrayClass.toTypeConstructor, List(tpe))).last - val newArrayApp = atPos(tree.pos) { + atPos(tree.pos) { val tag = resolveClassTag(tree.pos, tagType) if (tag.isEmpty) MissingClassTagError(tree, tagType) - else new ApplyToImplicitArgs(Select(tag, nme.newArray), args) + else typed(new ApplyToImplicitArgs(Select(tag, nme.newArray), args)) } - typed(newArrayApp, mode, pt) case Apply(Select(fun, nme.apply), _) if treeInfo.isSuperConstrCall(fun) => //SI-5696 TooManyArgumentListsForConstructor(tree) case tree1 => @@ -5264,7 +5264,7 @@ trait Typers extends Modes with Adaptations with Tags { def typedDocDef(docdef: DocDef) = { if (forScaladoc && (sym ne null) && (sym ne NoSymbol)) { - val comment = docdef.comment + val comment = docdef.comment docComments(sym) = comment comment.defineVariables(sym) val typer1 = newTyper(context.makeNewScope(tree, context.owner)) @@ -5595,12 +5595,18 @@ trait Typers extends Modes with Adaptations with Tags { "context.owner" -> context.owner ) ) - val tree1 = typed1(tree, mode, dropExistential(pt)) + typed1(tree, mode, dropExistential(pt)) + } + // Can happen during erroneous compilation - error(s) have been + // reported, but we need to avoid causing an NPE with this tree + if (tree1.tpe eq null) + return setError(tree) + + if (!alreadyTyped) { printTyping("typed %s: %s%s".format( ptTree(tree1), tree1.tpe, if (isSingleType(tree1.tpe)) " with underlying "+tree1.tpe.widen else "") ) - tree1 } tree1.tpe = addAnnotations(tree1, tree1.tpe) diff --git a/src/library/scala/collection/LinearSeqOptimized.scala b/src/library/scala/collection/LinearSeqOptimized.scala index 0f0a405a85..81cccea519 100755 --- a/src/library/scala/collection/LinearSeqOptimized.scala +++ b/src/library/scala/collection/LinearSeqOptimized.scala @@ -12,6 +12,7 @@ import generic._ import mutable.ListBuffer import immutable.List import scala.util.control.Breaks._ +import scala.annotation.tailrec /** A template trait for linear sequences of type `LinearSeq[A]` which optimizes * the implementation of several methods under the assumption of fast linear access. @@ -247,14 +248,17 @@ trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends Linea } override /*SeqLike*/ - def lengthCompare(len: Int): Int = { - var i = 0 - var these = self - while (!these.isEmpty && i <= len) { - i += 1 - these = these.tail + def lengthCompare(len: Int): Int = { + @tailrec def loop(i: Int, xs: Repr): Int = { + if (i == len) + if (xs.isEmpty) 0 else 1 + else if (xs.isEmpty) + -1 + else + loop(i + 1, xs.tail) } - i - len + if (len < 0) 1 + else loop(0, this) } override /*SeqLike*/ diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala index f65e2ef9cd..1be0dba29f 100644 --- a/src/library/scala/collection/SeqLike.scala +++ b/src/library/scala/collection/SeqLike.scala @@ -84,13 +84,17 @@ trait SeqLike[+A, +Repr] extends Any with IterableLike[A, Repr] with GenSeqLike[ * if computing `length` is cheap. */ def lengthCompare(len: Int): Int = { - var i = 0 - val it = iterator - while (it.hasNext && i <= len) { - it.next() - i += 1 + if (len < 0) 1 + else { + var i = 0 + val it = iterator + while (it.hasNext) { + if (i == len) return if (it.hasNext) 1 else 0 + it.next() + i += 1 + } + i - len } - i - len } override /*IterableLike*/ def isEmpty: Boolean = lengthCompare(0) == 0 diff --git a/test/files/neg/t6788.check b/test/files/neg/t6788.check new file mode 100644 index 0000000000..96a6f8b601 --- /dev/null +++ b/test/files/neg/t6788.check @@ -0,0 +1,5 @@ +t6788.scala:6: error: not found: value foo +Error occurred in an application involving default arguments. + s.copy(b = foo) + ^ +one error found diff --git a/test/files/neg/t6788.scala b/test/files/neg/t6788.scala new file mode 100644 index 0000000000..77949ed621 --- /dev/null +++ b/test/files/neg/t6788.scala @@ -0,0 +1,7 @@ +case class B[T](b: T, a: List[Int]) // need two args, B must be polymorphic + +class A { + var s: B[Int] = _ // has to be a var + + s.copy(b = foo) +} diff --git a/test/files/neg/t6829.check b/test/files/neg/t6829.check new file mode 100644 index 0000000000..8ee6d182eb --- /dev/null +++ b/test/files/neg/t6829.check @@ -0,0 +1,36 @@ +t6829.scala:35: error: type mismatch; + found : AgentSimulation.this.state.type (with underlying type G#State) + required: _10.State + lazy val actions: Map[G#Agent,G#Action] = agents.map(a => a -> a.chooseAction(state)).toMap + ^ +t6829.scala:45: error: trait AgentSimulation takes type parameters + pastHistory: List[G#State] = Nil) extends AgentSimulation + ^ +t6829.scala:47: error: class LearningSimulation takes type parameters + lazy val step: LearningSimulation = { + ^ +t6829.scala:49: error: not found: value actions + val (s,a,s2) = (state,actions(agent),nextState) + ^ +t6829.scala:49: error: not found: value nextState + val (s,a,s2) = (state,actions(agent),nextState) + ^ +t6829.scala:50: error: type mismatch; + found : s.type (with underlying type Any) + required: _54.State where val _54: G + val r = rewards(agent).r(s,a,s2) + ^ +t6829.scala:51: error: type mismatch; + found : s.type (with underlying type Any) + required: _51.State + agent.learn(s,a,s2,r): G#Agent + ^ +t6829.scala:53: error: not found: value nextState +Error occurred in an application involving default arguments. + copy(agents = updatedAgents, state = nextState, pastHistory = currentHistory) + ^ +t6829.scala:53: error: not found: value currentHistory +Error occurred in an application involving default arguments. + copy(agents = updatedAgents, state = nextState, pastHistory = currentHistory) + ^ +9 errors found diff --git a/test/files/neg/t6829.scala b/test/files/neg/t6829.scala new file mode 100644 index 0000000000..7cbe3c9542 --- /dev/null +++ b/test/files/neg/t6829.scala @@ -0,0 +1,64 @@ +package bugs + +/** + * Created with IntelliJ IDEA. + * User: arya + * Date: 12/18/12 + * Time: 4:17 PM + * To change this template use File | Settings | File Templates. + */ +object currenttype2 { + + type Reward = Double + + trait AbstractAgent[State,Action] { + type A = AbstractAgent[State,Action] + def chooseAction(s: State): Action + def startEpisode: A = this + def learn(s1: State, a: Action, s2: State, r: Reward): A + } + + case class RewardFunction[State,Action](r: (State,Action,State) => Reward) + + trait Rules[G<:GameDomain] { + def simulate(state: G#State, agentActions: List[(G#Agent,G#Action)]): G#State + } + + trait AgentSimulation[G<:GameDomain] { + val agents: List[G#Agent] + val state: G#State + val rewards: Map[G#Agent,G#Rewards] + val rules: Rules[G] + val pastHistory: List[G#State] + lazy val currentHistory = state :: pastHistory + + lazy val actions: Map[G#Agent,G#Action] = agents.map(a => a -> a.chooseAction(state)).toMap + lazy val nextState: G#State = rules.simulate(state, actions.toList) + + def step: AgentSimulation[G] + } + + case class LearningSimulation[G<:GameDomain](agents: List[G#Agent], + state: G#State, + rewards: Map[G#Agent,G#Rewards], + rules: Rules[G], + pastHistory: List[G#State] = Nil) extends AgentSimulation + { + lazy val step: LearningSimulation = { + val updatedAgents: List[G#Agent] = agents map { agent => + val (s,a,s2) = (state,actions(agent),nextState) + val r = rewards(agent).r(s,a,s2) + agent.learn(s,a,s2,r): G#Agent + } + copy(agents = updatedAgents, state = nextState, pastHistory = currentHistory) + } + } + + trait GameDomain { + domain => + type State + type Action + type Agent = AbstractAgent[State, Action] // agent supertype + type Rewards = RewardFunction[State,Action] + } + } diff --git a/test/files/pos/classtag-pos.flags b/test/files/pos/classtag-pos.flags new file mode 100644 index 0000000000..281f0a10cd --- /dev/null +++ b/test/files/pos/classtag-pos.flags @@ -0,0 +1 @@ +-Yrangepos diff --git a/test/files/pos/classtag-pos.scala b/test/files/pos/classtag-pos.scala new file mode 100644 index 0000000000..768d2e27f4 --- /dev/null +++ b/test/files/pos/classtag-pos.scala @@ -0,0 +1,5 @@ +import scala.reflect.runtime.universe._ + +class A { + def f[T: TypeTag] = typeOf[T] match { case TypeRef(_, _, args) => args } +} diff --git a/test/files/run/streams.check b/test/files/run/streams.check index 7f894052d9..db6d2eebab 100644 --- a/test/files/run/streams.check +++ b/test/files/run/streams.check @@ -1,5 +1,8 @@ Stream() Stream() +true +true +true Array(1) Stream(1, ?) @@ -8,12 +11,21 @@ Stream() Stream() Stream(1) Stream() +true +true +true +true Array(1, 2) Stream(2) Stream() Stream(1, 2) Stream() +true +true +true +true +true 999 512 @@ -23,3 +35,5 @@ Stream(100001, ?) true true 705082704 + +true diff --git a/test/files/run/streams.scala b/test/files/run/streams.scala index 51b4e5d76c..03b2622edd 100644 --- a/test/files/run/streams.scala +++ b/test/files/run/streams.scala @@ -2,6 +2,9 @@ object Test extends App { val s0: Stream[Int] = Stream.empty println(s0.take(1)) println(s0.takeWhile(_ > 0)) + println(s0.lengthCompare(-5) > 0) + println(s0.lengthCompare(0) == 0) + println(s0.lengthCompare(5) < 0) println val s1 = Stream.cons(1, Stream.empty) @@ -12,6 +15,10 @@ object Test extends App { println(s1.drop(2)) println(s1.drop(-1)) println(s1.dropWhile(_ > 0)) + println(s1.lengthCompare(-5) > 0) + println(s1.lengthCompare(0) > 0) + println(s1.lengthCompare(1) == 0) + println(s1.lengthCompare(5) < 0) println val s2 = s1.append(Stream.cons(2, Stream.empty)) @@ -20,6 +27,11 @@ object Test extends App { println(s2.drop(2)) println(s2.drop(-1)) println(s2.dropWhile(_ > 0)) + println(s2.lengthCompare(-5) > 0) + println(s2.lengthCompare(0) > 0) + println(s2.lengthCompare(1) > 0) + println(s2.lengthCompare(2) == 0) + println(s2.lengthCompare(5) < 0) println val s3 = Stream.range(1, 1000) //100000 (ticket #153: Stackoverflow) @@ -43,4 +55,12 @@ object Test extends App { println(Stream.from(1).take(size).foldLeft(0)(_ + _)) val arr = new Array[Int](size) Stream.from(1).take(size).copyToArray(arr, 0) + + println + + // ticket #6415 + lazy val x = { println("evaluated"); 1 } + val s4 = 0 #:: x #:: Stream.empty + + println(s4.isDefinedAt(0)) } diff --git a/test/files/run/t2544.check b/test/files/run/t2544.check index 716b146ac4..d19538dca3 100644 --- a/test/files/run/t2544.check +++ b/test/files/run/t2544.check @@ -2,8 +2,8 @@ 2 3 3 --2 --2 +-1 +-1 1 1 0 diff --git a/test/files/run/t2544.scala b/test/files/run/t2544.scala index 7e7cfeb357..6bee2f1082 100644 --- a/test/files/run/t2544.scala +++ b/test/files/run/t2544.scala @@ -1,19 +1,25 @@ object Test { object Foo extends Seq[Int] { def apply(i: Int) = i - def length = 4 + def length = 5 def iterator = Iterator(0,1,2,3,4) } + def lengthEquiv(result: Int) = println( + if (result < 0) -1 + else if (result == 0) 0 + else 1 + ) + def main(args: Array[String]) = { println(Foo indexWhere(_ >= 2,1)) println(Foo.toList indexWhere(_ >= 2,1)) println(Foo segmentLength(_ <= 3,1)) println(Foo.toList segmentLength(_ <= 3,1)) - println(Foo lengthCompare 7) - println(Foo.toList lengthCompare 7) - println(Foo lengthCompare 2) - println(Foo.toList lengthCompare 2) - println(Foo lengthCompare 5) - println(Foo.toList lengthCompare 5) + lengthEquiv(Foo lengthCompare 7) + lengthEquiv(Foo.toList lengthCompare 7) + lengthEquiv(Foo lengthCompare 2) + lengthEquiv(Foo.toList lengthCompare 2) + lengthEquiv(Foo lengthCompare 5) + lengthEquiv(Foo.toList lengthCompare 5) } -}
\ No newline at end of file +} |