Scala Compiler 2.8.0.RC2 problem regarding pattern matching statement?

Why the next module does not compile on Scala 2.8.RC [1,2]?

object Test { import util.matching.Regex._ val pVoid = """\s*void\s*""".r val pVoidPtr = """\s*(const\s+)?void\s*\*\s*""".r val pCharPtr = """\s*(const\s+)GLchar\s*\*\s*""".r val pIntPtr = """\s*(const\s+)?GLint\s*\*\s*""".r val pUintPtr = """\s*(const\s+)?GLuint\s*\*\s*""".r val pFloatPtr = """\s*(const\s+)?GLfloat\s*\*\s*""".r val pDoublePtr = """\s*(const\s+)?GLdouble\s*\*\s*""".r val pShortPtr = """\s*(const\s+)?GLshort\s*\*\s*""".r val pUshortPtr = """\s*(const\s+)?GLushort\s*\*\s*""".r val pInt64Ptr = """\s*(const\s+)?GLint64\s*\*\s*""".r val pUint64Ptr = """\s*(const\s+)?GLuint64\s*\*\s*""".r def mapType(t: String): String = t.trim match { case pVoid() => "Unit" case pVoidPtr() => "ByteBuffer" case pCharPtr() => "CharBuffer" case pIntPtr() | pUintPtr() => "IntBuffer" case pFloatPtr() => "FloatBuffer" case pShortPtr() | pUshortPtr() => "ShortBuffer" case pDoublePtr() => "DoubleBuffer" case pInt64Ptr() | pUint64Ptr() => "LongBuffer" case x => x } } 

UPDATE 1

Following the advice in the answer, the next problem is that the compilation takes too long. Interestingly, if I remove 2 of the above arguments, I get a follwing compiler error:

 object Test { import util.matching.Regex._ val PVoid = """\s*void\s*""".r val PVoidPtr = """\s*(const\s+)?void\s*\*\s*""".r val PCharPtr = """\s*(const\s+)GLchar\s*\*\s*""".r val PIntPtr = """\s*(const\s+)?GLint\s*\*\s*""".r val PUintPtr = """\s*(const\s+)?GLuint\s*\*\s*""".r val PFloatPtr = """\s*(const\s+)?GLfloat\s*\*\s*""".r val PDoublePtr = """\s*(const\s+)?GLdouble\s*\*\s*""".r val PShortPtr = """\s*(const\s+)?GLshort\s*\*\s*""".r val PUshortPtr = """\s*(const\s+)?GLushort\s*\*\s*""".r val PInt64Ptr = """\s*(const\s+)?GLint64\s*\*\s*""".r val PUint64Ptr = """\s*(const\s+)?GLuint64\s*\*\s*""".r def mapType(t: String): String = t.trim match { case PVoid() => "Unit" case PVoidPtr() => "ByteBuffer" case PCharPtr() => "CharBuffer" case PIntPtr() | PUintPtr() => "IntBuffer" case PFloatPtr() => "FloatBuffer" case PShortPtr() | PUshortPtr() => "ShortBuffer" case PDoublePtr() => "DoubleBuffer" case PInt64Ptr() | PUint64Ptr() => "LongBuffer" case x => x } } Exception in thread "main" java.lang.Error:ch.epfl.lamp.fjbg.JCode$OffsetTooBigException: offset too big to fit in 16 bits: 43772 at ch.epfl.lamp.fjbg.JFieldOrMethod.writeTo(JFieldOrMethod.java:114) at ch.epfl.lamp.fjbg.JClass.writeTo(JClass.java:315) 
+4
source share
1 answer

You are trying to use util.matching.Regex as an extractor template. You can do this because this class defines the unapplySeq method. When matching with samples, links to extractor templates should start with a capital letter.

 val PVoid = """\s*void\s*""".r def mapType(t: String): String = t.trim match { case PVoid() => "Unit" case x => x } 

UPDATE

Here's the full, compiled version of your code:

 object Test { import util.matching.Regex._ val PVoid = """\s*void\s*""".r val PVoidPtr = """\s*(const\s+)?void\s*\*\s*""".r val PCharPtr = """\s*(const\s+)GLchar\s*\*\s*""".r val PIntPtr = """\s*(const\s+)?GLint\s*\*\s*""".r val PUintPtr = """\s*(const\s+)?GLuint\s*\*\s*""".r val PFloatPtr = """\s*(const\s+)?GLfloat\s*\*\s*""".r val PDoublePtr = """\s*(const\s+)?GLdouble\s*\*\s*""".r val PShortPtr = """\s*(const\s+)?GLshort\s*\*\s*""".r val PUshortPtr = """\s*(const\s+)?GLushort\s*\*\s*""".r val PInt64Ptr = """\s*(const\s+)?GLint64\s*\*\s*""".r val PUint64Ptr = """\s*(const\s+)?GLuint64\s*\*\s*""".r def mapType(t: String): String = t.trim match { case PVoid() => "Unit" case PVoidPtr() => "ByteBuffer" case PCharPtr() => "CharBuffer" case PIntPtr() | PUintPtr() => "IntBuffer" case x => x match { case PFloatPtr() => "FloatBuffer" case PShortPtr() | PUshortPtr() => "ShortBuffer" case PDoublePtr() => "DoubleBuffer" case PInt64Ptr() | PUint64Ptr() => "LongBuffer" case x => x } } } 

Matching the pattern is split halfway to workaround # 1113 .

+3
source

Source: https://habr.com/ru/post/1310721/


All Articles