Skip to content
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

Block-scoped Option Statements #117

Open
AnthonyDGreen opened this issue Jun 28, 2017 · 9 comments
Open

Block-scoped Option Statements #117

AnthonyDGreen opened this issue Jun 28, 2017 · 9 comments

Comments

@AnthonyDGreen
Copy link
Contributor

AnthonyDGreen commented Jun 28, 2017

Because sometimes you only need it in that one method. Could potentially address scenario #135.

@AnthonyDGreen AnthonyDGreen added this to the VB16.0 candidate milestone Jun 28, 2017
@craigajohnson
Copy link

Please yes. At present, I sometimes maintain a partial class file with Option Strict Off at the top for the occasional late-binding scenario (which VB was famous for until...).

Method scoping would be superior, though - almost as good as Dynamic Dim x to scope it to the variable level but who am I to complain!?

@AdamSpeight2008
Copy link
Contributor

AdamSpeight2008 commented Jun 29, 2017

  • Option
Function F0()
  Option  Strict Off
  Imports System.Text

End Function

This currently parses but produces an error Statement is not valid in a method on both statements, which could be made conditional feature, dependant of language version.
This is highly likely a breaking change.


  • Local Option
Function F1()
  Local Option  Strict Off
  Local Imports System.Text

End Function

We could introduce a new contextual keyword Local that would prefix the previous statements and make them into local statements.
This also permits an additional code-fix Make Local Option / Make Local Imports


  • Using Option ... End Using
    Another option would be to extend the scope of usage of an existing construct, like;-
    Using ... End Using
Function F2()
  Using Option  Strict Off
  Using Imports System.Text

  End Using
  End Using
End Function

Using does permit concatenating multiple usage into a single statement.

Function F3()
  Using Option Strict Off, Imports System.Text

  End Using
End Function

@AnthonyDGreen
Why not extend this feature to localising to any NamespaceMemberDeclaraion (vb spec) construction?

@AnthonyDGreen
Copy link
Contributor Author

@AdamSpeight2008 How is that highly likely a breaking change? The statements aren't allowed in methods today and then they would be. That's not a breaking change.

Re: Namespace scoped Imports, as one former language designer put it "We probably put those in C# because of Java and if we had to do it over again we problem wouldn't". They add a lot of complexity everywhere (compiler, IDE) for not a whole lot of benefit.

@AnthonyDGreen
Copy link
Contributor Author

The VB LDM looked at this issue on August 23rd and would like this proposal to go further. We also would like method-scoped Imports (which might be evil) to be put into a separate proposal. If we add an Option Checked statement (Proposal #33) for checked/unchecked arithmetic then those proposals combined would address #84 nicely without the weight of a checked/unchecked block. We'd also like to discuss making this block-scoped rather than method-scoped.

@AnthonyDGreen AnthonyDGreen self-assigned this Sep 13, 2017
@AnthonyDGreen AnthonyDGreen changed the title Method scoped Imports and Option statements Method scoped Option statements Sep 19, 2017
@AnthonyDGreen AnthonyDGreen changed the title Method scoped Option statements Block scoped Option statements Sep 19, 2017
@AnthonyDGreen AnthonyDGreen changed the title Block scoped Option statements Block-scoped Option Statements Sep 19, 2017
@paul1956
Copy link

Would this allow VB to support unchecked like in C#? If not where is a good place to discuss that?

@reduckted
Copy link
Contributor

@paul1956, given that there is currently no Option to turn on/off unchecked arithmetic, I would assume not.

#33 does talk about an Option Unchecked, but also other possibilities like Unchecked/End Unchecked.
#84 is another one, but it seems like a duplicate of #33.

@paul1956
Copy link

#33 seems orphaned but I think getting it revived as part of this would be welcome.

@ghost
Copy link

ghost commented Feb 16, 2018

FYI just found out that source level option strict on/off is already possible.
Just the needed syntax sucks:

  1. In project properties - compile, switch off Warnings as Errors if this is on.
  2. Set the top 3 errors (Implicit conversion, Late binding; call could fail at runtime and Implicit type; object assumed) to Warning.
  3. Switch on Warnings as errors if you like.

Now in the code you can use "#Disable Warning BC42017, BC42016" to disable option strict and "#Enable Warning BC42017, BC42016" to enable option strict again.

By example the following code will compile (but will crash) between those compiler switches:

#Disable Warning BC42017, BC42016
        Dim x As Object = 123.0
        x.abc = 3
#Enable Warning BC42017, BC42016

So I don't think it should be very hard to implement this as:

#Option Strict Off 
        Dim x As Object = 123.0
        x.abc = 3
#Option Strict On

@JustNrik
Copy link

JustNrik commented Nov 6, 2018

I prefer #Option Strict On/Off the most. If anything, I'd like With or Using keywords.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants