Code Monkey home page Code Monkey logo

nocapture's People

Contributors

bessgeor avatar hellbrick avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bessgeor

nocapture's Issues

IndexOutOfRangeException when analyzing params[] method invocations

		[Fact]
		public void CapturingArgumentPassedToNoCaptureParamsItemIsReported()
			=> _verifier
			.Source
			(
@"
using System;

[AttributeUsage( AttributeTargets.Parameter | AttributeTargets.Method )]
class NoCaptureAttribute : Attribute
{
}

class C
{
	private readonly int _field = 42;

	void CallSite() => Invoke( 64, x => x + 2, x => _field + x );
	T Invoke<T>( T initialValue, [NoCapture] params Func<T, T>[] transforms ) => initialValue;
}
"
			)
			.ShouldHaveDiagnostic( "Invoke", "transforms", "this" );

False positive when local method references `this` but not in the analyzed lambda

		[Fact]
		public void NoFalsePositiveForNonCapturingLambdaInsideLocalMethod()
			=> _verifier
			.Source
			(
@"
using System;
using System.Collections.Generic;
using System.Linq;

[AttributeUsage( AttributeTargets.Parameter | AttributeTargets.Method )]
class NoCaptureAttribute : Attribute
{
}

class C
{
	private readonly int[] _numbers = { 42, 64, 128 };

	public IEnumerable<int> EnumerateNumbers()
	{
		return
			_numbers == null
			? Enumerable.Empty<int>()
			: EnumerateWithoutValidation();

		IEnumerable<int> EnumerateWithoutValidation()
			=> _numbers
			.WhereNoCapture( x => x == 42 );
	}
}

static class X
{
		public static IEnumerable<T> WhereNoCapture<T>( this IEnumerable<T> sequence, [NoCapture] Func<T, bool> predicate )
			=> sequence.Where( predicate );
}
"
			)
			.ShouldHaveNoDiagnostics();

Assert.Empty() Failure
Collection: [Test0.cs(24,21): error HBNoCapture: WhereNoCapture( predicate ) doesn't allow capturing lambdas. Captured variables: this.]
at HellBrick.Diagnostics.Assertions.AnalyzerVerifier`3.ShouldHaveNoDiagnostics() in F:\Software\NoCapture\HellBrick.Diagnostics.Assertions\AnalyzerVerifier.cs:line 44
at HellBrick.NoCapture.Analyzer.Test.NoCaptureTest.NoFalsePositiveForNonCapturingLambdaInsideLocalMethod() in F:\Software\NoCapture\HellBrick.NoCapture.Test\NoCaptureTest.cs:line 171

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.