Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,12 @@ public Type visitTypeVariable(TypeVariable t, Type parameterized) {
@Override
public Type visitDeclared(DeclaredType t, Type parameterized) {
if ( types.isAssignable( types.erasure( t ), types.erasure( parameterized.getTypeMirror() ) ) ) {
// if same type, we can cast en assume number of type args are also the same
// We can't assume that the type args are the same
// e.g. List<T> is assignable to Object
if ( t.getTypeArguments().size() != parameterized.getTypeParameters().size() ) {
return super.visitDeclared( t, parameterized );
}

for ( int i = 0; i < t.getTypeArguments().size(); i++ ) {
Type result = visit( t.getTypeArguments().get( i ), parameterized.getTypeParameters().get( i ) );
if ( result != null ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._2263;

import org.mapstruct.Mapper;

/**
* @author Filip Hrisafov
*/
@Mapper
public interface Erroneous2263Mapper {

Target map(Source source);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._2263;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;

/**
* @author Filip Hrisafov
*/
@IssueKey("2263")
@RunWith(AnnotationProcessorTestRunner.class)
@WithClasses({
Erroneous2263Mapper.class,
Source.class,
Target.class,
})
public class Issue2263Test {

@Test
@ExpectedCompilationOutcome(value = CompilationResult.FAILED,
diagnostics = {
@Diagnostic(type = Erroneous2263Mapper.class,
kind = javax.tools.Diagnostic.Kind.ERROR,
line = 16,
message = "Can't map property \"Object value\" to \"String value\". " +
"Consider to declare/implement a mapping method: \"String map(Object value)\".")
})
public void shouldCorrectlyReportUnmappableTargetObject() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._2263;

/**
* @author Filip Hrisafov
*/
public class Source {

private final Object value;

public Source(Object value) {
this.value = value;
}

public Object getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._2263;

/**
* @author Filip Hrisafov
*/
public class Target {

private final String value;

public Target(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}