This repository was archived by the owner on Sep 1, 2020. It is now read-only.
forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 19
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This requires -Xexperimental in 2.11.x. Update spec. TODO: - test! - include SIP as spec addendum - don't predicate on -Xexperimental -- introduce -Xsip:23? Notes: - `()` is not a literal, neither are `Symbol`s
`LiteralType` is a `SingleType` with a literal for its path. With an example: `1` is to `p.type`, as `1` is to `p`. `lit` is the most precise type for an expression known to evaluate to `lit`. Note that we cannot constant fold the expression to `lit`, since it may have a side effect. `ConstantType(c)` is the type of an expression that can be constant folded to `c`. When an expressions should not be constant folded, the corresponding `LiteralType` is created: `ConstantType(c).deconst == LiteralType(c)` (this is where all `LiteralType`s originate, except for unpickling). `typedLiteral` always infers a `ConstantType`, which is subsequently `deconst`ed or `widen`ed where necessary (see `widenIfNecessary`). In short, only `final val`s may have `ConstantType`s, and `widen`ing is required to ensure that a path is stable and accessible (roughly speaking). When checking subtyping, this invariant is useful: `LiteralType(c).widen == c.tpe`. TODO: - test! (subtyping, type inference, type tests, patmat, dependent method types) - fully predicate implementation on -Xsip:23 - is it safe to reduce LITERAL in pickler?
test case: ``` val y: 5 = 5 def g(x: Int) = x match { case _: y.type => 0 } ```
Before: sandbox/test.scala:2: error: type mismatch; found : Array[1] required: Array[Int]
TODO: deriving this from type param bounds is not the best way, should consider all constraints that we encounter scala> def stable[T <: 1](x: T): T = x stable: [T <: 1](x: T)T scala> stable(1) res0: 1 = 1 scala> stable(2) <console>:9: error: inferred type arguments [2] do not conform to method stable's type parameter bounds [T <: 1] stable(2) ^ <console>:9: error: type mismatch; found : Int(2) required: T stable(2) ^ scala> def stable[T <: Singleton](x: T): T = x stable: [T <: Singleton](x: T)T scala> val x: Int = 2 x: Int = 2 scala> val y: x.type = x y: x.type = 2 scala> stable(y) res3: x.type = 2
e.g., val x : -1 => -1 = ???
this bootstraps
6eedb21
to
e04c588
Compare
propensive
pushed a commit
that referenced
this pull request
Nov 15, 2014
@propensive That thing had test failures! Sorry for not telling you before, I'll come up with a PR that fixes them soon :) |
Aargh. Whoops! I was blinded by my own trigger-happy excitement! On 15 November 2014 01:27, George Leontiev [email protected] wrote:
Jon Pretty | @propensive |
This was referenced Nov 16, 2014
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'll just open this PR with @adriaanm's work on SIP-23 here to spawn some conversations. This implementation seems to solve all the issues I've been seeing in #45.