Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3242412
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:18:45+00:00 2026-05-17T18:18:45+00:00

Is it a bug in Scala 2.8.0 ? (the same happens with 2.8.1.RC2) import

  • 0

Is it a bug in Scala 2.8.0 ? (the same happens with 2.8.1.RC2)

import junit.framework._
import Assert._

class BugTest extends TestCase {

  def compare(first: Any, second: Any): Int = {
      (first, second) match {
        case (k: Int, o: Int) => k compare o
        //why the next case matches (Float, Int) but does not match (Int, Float) ???
        case (k: Number, o: Number) => k.doubleValue() compare o.doubleValue()
        case _ => throw new Exception("Unsupported compare " + first + "; " + second)
    }
  }

  def testCompare() {
    assertEquals("Both Int", -1, compare(0, 1))
    assertEquals("Both Float", 1, compare(1.0, 0.0))
    assertEquals("Float then Int", 0, compare(10.0, 10))
    assertEquals("Int then Float", 0, compare(10, 10.0))//this fails with an exception
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:18:45+00:00Added an answer on May 17, 2026 at 6:18 pm

    I think this is a bug. If you look at the generated bytecode:

    
    public int compare(java.lang.Object, java.lang.Object);
      Code:
       Stack=4, Locals=7, Args_size=3
       0:   aload_1
       1:   astore_3
       2:   aload_2
       3:   astore  4
       5:   aload_3
       6:   instanceof  #8; //class java/lang/Integer
       9:   ifeq    81
       12:  aload_3
       13:  invokestatic    #14; //Method scala/runtime/BoxesRunTime.unboxToInt:(Ljava/lang/Object;)I
       16:  istore  5
       18:  aload   4
       20:  instanceof  #8; //class java/lang/Integer
       23:  ifeq    45
       26:  getstatic   #20; //Field scala/Predef$.MODULE$:Lscala/Predef$;
       29:  iload   5
       31:  invokevirtual   #24; //Method scala/Predef$.intWrapper:(I)Lscala/runtime/RichInt;
       34:  aload   4
       36:  invokestatic    #14; //Method scala/runtime/BoxesRunTime.unboxToInt:(Ljava/lang/Object;)I
       39:  invokevirtual   #29; //Method scala/runtime/RichInt.compare:(I)I
       42:  goto    124
       45:  new #31; //class java/lang/Exception
    
       //part omitted for brevity..
    
       81:  aload_3
       82:  instanceof  #54; //class java/lang/Number
       85:  ifeq    161
       88:  aload_3
       89:  checkcast   #54; //class java/lang/Number
       92:  astore  6
       94:  aload   4
       96:  instanceof  #54; //class java/lang/Number
       99:  ifeq    125
       102: getstatic   #20; //Field scala/Predef$.MODULE$:Lscala/Predef$;
       105: aload   6
       107: invokevirtual   #58; //Method java/lang/Number.doubleValue:()D
       110: invokevirtual   #62; //Method scala/Predef$.doubleWrapper:(D)Lscala/runtime/RichDouble;
       113: aload   4
       115: checkcast   #54; //class java/lang/Number
       118: invokevirtual   #58; //Method java/lang/Number.doubleValue:()D
    
    

    In line 6, the check is done whether the first variable is an instance of java.lang.Integer. If this does not succeed, we continue at line 81, which starts with the java.lang.Number check. If the first variable is an Integer, then we continue with the same check for the second variable. However, if this second check does not succeed, instead of again continuing at line 81 with the Number check, a jump is made to line 45, which throws the Exception. That does not seem to be correct. I quickly browsed through trac but couldn’t directly find an issue regarding this, so it may be sensible to create one.

    Edit
    As Extempore pointed out, it is a bug that is already in trac, see his comment below.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the file bug.scala : package sandbox object Foo { implicit def stringToInt(s: String)
Have a look at the following Scala example: class A { def foo(x: Int):
scala> class A(implicit a: Int); defined class A scala> class B()(implicit a: Int); defined
EDIT: This was an old bug long since fixed in Scala 2.8 and later
Using Scala's command line REPL: def foo(x: Int): Unit = {} def foo(x: String):
Please consider the following test program (using scala 2.9.0.1) object test { def main(args:Array[String])
I'm trying to define a generic residue class ring in Scala. A residue class
MDI Bug http://www.dicu.com/pics/bug_mdi.jpg That's what I get when I try to automatically maximize MDI
The bug starts at cin.getline ( string, 25, '\n' ); or the line below
A bug has been filed and fixed (super quickly) in SWT: https://bugs.eclipse.org/bugs/show_bug.cgi?id=305294 Just to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.