diff options
author | Martin Odersky <odersky@gmail.com> | 2014-01-06 08:58:31 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-01-06 08:58:39 +0100 |
commit | 6b3f2225a8d6de898ca9a2299570056807de1a92 (patch) | |
tree | c9bf818777819c7a6e748033cf1bf571e428d60a | |
parent | 7b30d5b7a9fe7d89a252d8d9a07fd4c009e49a0d (diff) | |
download | dotty-6b3f2225a8d6de898ca9a2299570056807de1a92.tar.gz dotty-6b3f2225a8d6de898ca9a2299570056807de1a92.tar.bz2 dotty-6b3f2225a8d6de898ca9a2299570056807de1a92.zip |
Change to computing of unapply patterns.
If scrutinee has a get method with a product result type, assume the product members as pattern arguments only if there are more than one argument patterns. Without this tweak, the pattern
Some((x, y))
would not typecheck, as the extractor result type is Option[(S, T)], so normally two patterns of type S and T would be expected. Interestingly, with the tweak we still get a sort of auto-detupling.
Some(x, y)
would also work (did before the change, and still does now).
-rw-r--r-- | src/dotty/tools/dotc/config/OutputDirs.scala | 6 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Applications.scala | 3 |
2 files changed, 5 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/config/OutputDirs.scala b/src/dotty/tools/dotc/config/OutputDirs.scala index 8b81ba992..a87eb9bce 100644 --- a/src/dotty/tools/dotc/config/OutputDirs.scala +++ b/src/dotty/tools/dotc/config/OutputDirs.scala @@ -39,7 +39,7 @@ class OutputDirs { /** Set the single output directory. From now on, all files will * be dumped in there, regardless of previous calls to 'add'. */ - def setSingleOutput(outDir: String) { + def setSingleOutput(outDir: String): Unit = { val dst = AbstractFile.getDirectory(outDir) setSingleOutput(checkDir(dst, outDir, true)) } @@ -49,11 +49,11 @@ class OutputDirs { /** Set the single output directory. From now on, all files will * be dumped in there, regardless of previous calls to 'add'. */ - def setSingleOutput(dir: AbstractFile) { + def setSingleOutput(dir: AbstractFile): Unit = { singleOutDir = Some(dir) } - def add(src: AbstractFile, dst: AbstractFile) { + def add(src: AbstractFile, dst: AbstractFile): Unit = { singleOutDir = None outputDirs ::= ((src, dst)) } diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 47b10c4aa..6514a6a01 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -598,7 +598,8 @@ trait Applications extends Compatibility { self: Typer => } def seqSelector = defn.RepeatedParamType.appliedTo(unapplyResult.elemType :: Nil) def getSelectors(tp: Type): List[Type] = - if (defn.isProductSubType(tp)) productSelectors(tp) else tp :: Nil + if (defn.isProductSubType(tp) && args.length > 1) productSelectors(tp) + else tp :: Nil def getTp = extractorMemberType(unapplyResult, nme.get) // println(s"unapply $unapplyResult ${extractorMemberType(unapplyResult, nme.isDefined)}") |