Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: Scala 2.9.0-1, Scala 2.9.1
    • Fix Version/s: None
    • Component/s: Misc Compiler
    • Labels:
      None
    • Environment:

      Both interpreted and compiled code.

      Description

      The following code should not compile.

      scala> object Foo

      { val 1 = 2 }

      defined module Foo

      Also, as been pointed out by Seth Tisue, the defined val shadows the corresponding integer literal, producing unexpected behavior:

      scala> object O

      { val 1 = 2; def x = 1 }

      defined module O

      scala> O.x
      scala.MatchError: 2 (of class java.lang.Integer)

        Activity

        Hide
        Paul Phillips added a comment -

        "val 1 = 2" compiling is according to spec.

        PatVarDef ::= ‘val’ PatDef
        PatDef    ::= Pattern2 ‘=’ Expr
        Pattern2  ::= Literal
        

        It's not so according to spec that one can redefine the literal 1.

        Show
        Paul Phillips added a comment - "val 1 = 2" compiling is according to spec. PatVarDef ::= ‘val’ PatDef PatDef ::= Pattern2 ‘=’ Expr Pattern2 ::= Literal It's not so according to spec that one can redefine the literal 1.
        Hide
        Paul Phillips added a comment -

        Oh yeah, that's the object constructor throwing that exception. In that case it's all as expected.

        Show
        Paul Phillips added a comment - Oh yeah, that's the object constructor throwing that exception. In that case it's all as expected.
        Hide
        Seth Tisue added a comment - - edited

        Indeed, val definitions that don't bind any variables are actually explicitly speced. See SLS 4.1: "If p has no bound variables..."

        There is much discussion of this issue at https://groups.google.com/forum/#!topic/scala-user/k57U6jt8Za0

        Surely this is a bug though:

        Welcome to Scala version 2.9.1.RC4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
        Type in expressions to have them evaluated.
        Type :help for more information.
        
        scala> { val 1 = 2 }
        scala.MatchError: 2 (of class java.lang.Integer)
        
        scala> val 1 = 2
        
        scala> 
        

        No error there at the end, just "OK boss!"

        Shall I open a separate ticket on it? Or shall we reopen this one?

        Show
        Seth Tisue added a comment - - edited Indeed, val definitions that don't bind any variables are actually explicitly speced. See SLS 4.1: "If p has no bound variables..." There is much discussion of this issue at https://groups.google.com/forum/#!topic/scala-user/k57U6jt8Za0 Surely this is a bug though: Welcome to Scala version 2.9.1.RC4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26). Type in expressions to have them evaluated. Type :help for more information. scala> { val 1 = 2 } scala.MatchError: 2 (of class java.lang.Integer) scala> val 1 = 2 scala> No error there at the end, just "OK boss!" Shall I open a separate ticket on it? Or shall we reopen this one?
        Hide
        Seth Tisue added a comment -

        I opened SI-4950 on the REPL part of this.

        Show
        Seth Tisue added a comment - I opened SI-4950 on the REPL part of this.

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Aleksey Nikiforov
          • Votes:
            4 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development