views:

77

answers:

3

I noticed that if I leave off the terminating double quote for a string constant in Visual Studio 2010, there is no error or even a warning, i.e.

Dim foo as String = "hi

However, the continuous integration tool we are using flags an error:

error BC30648: String constants must end with a double quote.

What's going on here? Is there some language rule in VB.Net that makes a terminating double quote optional "sometimes"? Is there some setting in Visual Studio that will make it flag this as an error, so I can avoid "breaking the build" in this way?

A: 

I noticed if you have this option on, "Pretty listing (reformatting) of code" Visual Studio will add the the terminating double quote for you, whether you want it or not.

With that option off it allows the, what seems to be, invalid syntax.

Bedwell
A: 

That's not according to spec as section 2.4.4 of the spec states:

A string literal is a sequence of zero or more Unicode characters beginning and ending with an ASCII double-quote character

http://msdn.microsoft.com/en-us/library/aa711651%28v=VS.71%29.aspx

Normally Visual Studio will automatically add the ending double quote if you don't type one in. I wouldn't be surprised if it's related to this (maybe the testing never picked it up because they always got added or similar).

ho1
But the problem is they are NOT being added! The build and local testing goes fine WITHOUT the quote and the code gets checked in that way!
JoelFan
Yes, I meant that maybe the developers assumed that they would be added so they forgot to test for it. However Icemanind seems to have the correct answer rather than just a guess.
ho1
+2  A: 

Actually, historically, the BASIC language never REQUIRED a closing quote. This dates back to the 70's. GW-Basic, BasicA, QBASIC, QuickBasic, even older Tandy and TRS-80 computers NEVER required a closing quote. This is nothing new. The reason for this is because BASIC is not a free flow language, like C or C#. This means that whenever a newline is found, BASIC knows that your string must end, quoted or not. Microsoft has purposely not enforced this rule in order to be compatible with older code.

icemanind
Fair enough... so why is the build server flagging it as an error?
JoelFan
Because the compiler doesn't require it per se, however, it will be flagged as an error because it is, indeed, bad form. There should be a switch you can use to make the check not so "strict".
icemanind