wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let temp = 46; temp += 1;
let mut temp = 46; temp += 1;
Need mut to modify.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
[x*x for x in items if x > 81]
[x*x for x in items if x > 81]
Correct list comprehension.
Python
$data[8]
if ($data.Count -gt 8) {{ $data[8] }}
Check bounds.
PowerShell
echo 'world'
echo 'world';
Add semicolon.
PHP
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
function handle(bar) print(bar) end
function handle(bar) print(bar) end
Correct.
Lua
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
let list=vec![78,3,81]; let first=&list[0]; list.push(8);
let mut list=vec![78,3,81]; let first=list[0]; list.push(8);
Copy instead of reference.
Rust
for i=1,2 do print(i) end
for i=1,2 do print(i) end
Correct.
Lua
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
val val = 7; val = 37
var val = 7; val = 37
Use var for reassignment.
Scala
local y = 41
local y = 41
Correct.
Lua
print 'value'
print 'value';
Add semicolon.
Perl
count = 3
count=3
No spaces.
Shell
function compute(z:string){{return z;}} compute(81);
function compute(z:string){{return z;}} compute('hello');
Pass correct type.
TypeScript
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
a > 85 & b < 46
a > 85 and b < 46
Use 'and' not '&'.
Python
String index = 'result';
String index = "result";
Double quotes.
Java
String name = 'value';
String name = 'value';
Correct.
Dart
<input type='text' value='value'>
<input type='text' value='value' name='id'>
Add name attribute.
HTML
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
class Person def method end end
class Person def method end end
Correct.
Ruby
my @arr = (66,61,2);
my @arr = (66,61,2);
Correct.
Perl
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
var x = 52;
var x = 52;
Correct.
Dart
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if c > 31 print('result')
if c > 31: print('result')
Colon missing after if.
Python
for (int i=0; i<46; i++) {{}}
for (int i=0; i<46; i++) {{}}
Correct.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
{{"id":"message" "value":58}}
{{"id":"message", "value":58}}
Add comma.
JSON
if (b = 59)
if (b == 59)
Use ==.
Scala
if ($x = 22)
if ($x == 22)
Use ==.
Perl
def render puts 'info' end
def render puts 'info' end
Correct.
Ruby
let val = 'test'
let val = "test"
Double quotes.
Swift
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int c = 'hello';
String c = 'hello';
Type mismatch.
Dart
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
let temp: i32 = "info";
let temp: &str = "info";
Type mismatch.
Rust
if y = 54
if y == 54
Use ==.
Go
<person age=62>
<person age="62">
Quote attribute.
XML
{{"name":"world",}}
{{"name":"world"}}
Remove trailing comma.
JSON
arr(57)
if length(arr) >= 57, arr(57), end
Check length.
MATLAB
[27, 49, 14
[27, 49, 14]
Close bracket.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let mut z=95; let r1=&mut z; let r2=&mut z;
let mut z=95; {{ let r1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
const x;
const x = 50;
Initialize const.
JavaScript
class User {{ int item; }} obj.item=5;
class User {{ public int item; }} obj.item=5;
Make field public.
Java
'82' + 48
82 + 48
Avoid string coercion.
JavaScript
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
let y: number | null = null; y.toFixed(54);
let y: number | null = null; if(y!==null) y.toFixed(54);
Null check.
TypeScript
count = output
count = 'output'
Quote strings.
Python
if (a = 85) {{}}
if (a == 85) {{}}
Use ==.
Java
let text1 = String::from("value"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
let a: Int = 'test'
let a: String = 'test'
Fix type.
Swift
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
test
test()
Add parentheses.
Swift
arr[24]
if (arr.indices.contains(24)) arr[24]
Check index.
Kotlin
val num = 'data'
val num = "data"
Double quotes.
Kotlin
UPDATE users SET id='output' WHERE role=81
UPDATE users SET id='output' WHERE role=81;
Add semicolon.
SQL
class User {{ int b; }} obj.b=5;
class User {{ public int b; }} obj.b=5;
Make field public.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<input type='text' value='result'>
<input type='text' value='result' name='value'>
Add name attribute.
HTML
process
process()
Add parentheses.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class Order def method end end
class Order def method end end
Correct.
Ruby
my @arr = (66,64,93);
my @arr = (66,64,93);
Correct.
Perl
String count = 'world';
String count = "world";
Double quotes.
Java
local data = 95
local data = 95
Correct.
Lua
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
<person age=41>
<person age="41">
Quote attribute.
XML
SELECT * FROM users WHRE id=10;
SELECT * FROM users WHERE id=10;
Fix WHERE.
SQL
<user><name>hello</name><age>26</age></user
<user><name>hello</name><age>26</age></user>
Add closing >.
XML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
cin >> index;
int index; cin >> index;
Declare variable.
C++
var x int
var x int
Correct.
Go
h1 {{ font-size:39px color:#333; }}
h1 {{ font-size:39px; color:#333; }}
Add semicolon.
CSS
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
if b > 40 print('info')
if b > 40: print('info')
Colon missing after if.
Python
[x*x for x in list if x > 48]
[x*x for x in list if x > 48]
Correct list comprehension.
Python
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for i=1,89 do print(i) end
for i=1,89 do print(i) end
Correct.
Lua
def render(c): return c + 1
def render(c): return c + 1
Correct.
Python
fn handle() -> i32 {{ 51 }}
fn handle() -> i32 {{ 51 }}
Correct.
Rust
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
os.sqrt(94)
import os os.sqrt(94)
Import module first.
Python
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
index == '93'
index === 93
Use strict equality.
JavaScript