Skip to content

Fixes @unchecked warnings #2168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 4, 2017
Merged

Fixes @unchecked warnings #2168

merged 3 commits into from
Apr 4, 2017

Conversation

allanrenucci
Copy link
Contributor

  • Fixe the few @unchecked warnings emitted when compiling dotty.
  • Replace a map by mapConserve in UntypedTreeMap

dotty fails to compile the files I modified. Not sure if this reveals a bug or if it is a known incompatibility between scalac and dotty

-- Error: dotty/compiler/../compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala 
542 |    def unapply(tree: Tree @unchecked): Option[Type] = tree match {
    |                           ^^^^^^^^^^
    |                      annotation.unchecked does not have a constructor
-- [E007] Type Mismatch Error: dotty/compiler/../compiler/src/dotty/tools/dotc/transform/PostTyper.scala 
267 |            case ident @ Ident(_)                 => checkIdent(ident)
    |                                                                ^^^^^
    |found:    dotty.tools.dotc.ast.Trees.Ident[dotty.tools.dotc.ast.Trees.Untyped](ident)
    |required: dotty.tools.dotc.ast.tpd.Ident

@smarter
Copy link
Member

smarter commented Apr 3, 2017

-- Error: dotty/compiler/../compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
542 | def unapply(tree: Tree @unchecked): Option[Type] = tree match {
| ^^^^^^^^^^
| annotation.unchecked does not have a constructor

This looks like a bug but I have no idea why. Does (tree: @unchecked) match work ? In any case we should open an issue for this bug and try to minimize it.

-- [E007] Type Mismatch Error: dotty/compiler/../compiler/src/dotty/tools/dotc/transform/PostTyper.scala
267 | case ident @ Ident(_) => checkIdent(ident)
| ^^^^^

Dotty is correct here, ident refer to a member of Import#selectors which is untyped, checkIdent needs to be changed to take an untpd Ident instead of a typed Ident:

def checkIdent(ident: untpd.Ident): Unit = {

@@ -159,7 +159,7 @@ class TreeBuffer extends TastyBuffer(50000) {
val tree = it.next
treeAddrs.get(tree) match {
case addr: Addr => treeAddrs.put(tree, adjusted(addr))
case addrs: List[Addr] => treeAddrs.put(tree, addrs.map(adjusted))
case addrs: List[Addr @unchecked] => treeAddrs.put(tree, addrs.map(adjusted))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried just removing this line? Looks like the definition of treeAddrs has changed and it canno longer contains lists.

@@ -145,7 +145,7 @@ class TreeChecker extends Phase with SymTransformer {
override def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) = ()

def withDefinedSym[T](tree: untpd.Tree)(op: => T)(implicit ctx: Context): T = tree match {
case tree: DefTree =>
case tree: DefTree @unchecked =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, it's nice to add a comment explaining why @unchecked is correct here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smarter Not sure why this is correct here. tree is an untpd.Tree but the type test is on tpd.DefTree

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah looking at it, it should be an untpd.DefTree. Same thing for case t: MemberDef below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also means changing everDefinedSyms to be a mutable.HashMap[Symbol, untpd.Tree]

@allanrenucci
Copy link
Contributor Author

@smarter I was able to minimise the bug with @unchecked. A quick fix is to remove the import

import annotation.unchecked

@unchecked
class Test

@smarter
Copy link
Member

smarter commented Apr 4, 2017

@allanrenucci Cool! Could you open an issue?

@allanrenucci
Copy link
Contributor Author

@smarter #2170

@smarter
Copy link
Member

smarter commented Apr 4, 2017

LGTM!

@smarter smarter merged commit 42c2a6f into scala:master Apr 4, 2017
@allanrenucci allanrenucci deleted the warnings branch April 4, 2017 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants