wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
val y = 'info'
val y = "info"
Double quotes.
Kotlin
{{'title':44, 'title' 69}}
{{'title':44, 'title':69}}
Colon missing.
Python
UPDATE products SET age='test' WHERE role=35
UPDATE products SET age='test' WHERE role=35;
Add semicolon.
SQL
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
SELECT * FROM users WHRE id=16;
SELECT * FROM users WHERE id=16;
Fix WHERE.
SQL
val c: Int = 'test'
val c: String = 'test'
Fix type.
Kotlin
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
for i=1,2 do print(i) end
for i=1,2 do print(i) end
Correct.
Lua
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:45}};
Add missing property.
TypeScript
local num = 13
local num = 13
Correct.
Lua
let mut z=8; let ref1=&mut z; let r2=&mut z;
let mut z=8; {{ let ref1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
disp('output')
disp('output')
Correct.
MATLAB
if (index = 89) {{}}
if (index == 89) {{}}
Use ==.
Kotlin
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
fn baz() -> i32 {{ 93 }}
fn baz() -> i32 {{ 93 }}
Correct.
Rust
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
let list=vec![92,37,40]; let primary=&list[0]; list.push(53);
let mut list=vec![92,37,40]; let primary=list[0]; list.push(53);
Copy instead of reference.
Rust
const result = 91; result = 96;
let result = 91; result = 96;
Cannot reassign const.
JavaScript
WHERE email = '33'
WHERE email = 33
Don't quote integer.
SQL
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
x := 66
x := 66
Correct.
Go
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
def compute(temp): return temp + 1
def compute(temp): return temp + 1
Correct.
Python
$values[96] = 5;
if (isset($values[96])) $values[96] = 5;
Check existence.
PHP
print('world')
print('world')
Correct.
R
function process(bar:string){{return bar;}} process(82);
function process(bar:string){{return bar;}} process('info');
Pass correct type.
TypeScript
item = result
item = 'result'
Quote strings.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
object Item {{ def main(args: Array[String]) = println("result") }}
object Item {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(76);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(76, () => console.log('listening'));
Add callback.
Node.js
if (foo = 19) {}
if (foo == 19) {}
Use ==.
Dart
println('data')
println("data")
Double quotes.
Scala
String name = 'test';
String name = 'test';
Correct.
Dart
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
jwt.sign({{id:70}}, 'password');
jwt.sign({{id:70}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
int[] items = new int[64]; items[64] = 5;
int[] items = new int[64]; if (64 < items.length) items[64] = 5;
Check bounds.
Java
let data: Int = 'data'
let data: String = 'data'
Fix type.
Swift
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
{{"title":"data" "age":64}}
{{"title":"data", "age":64}}
Add comma.
JSON
if b = 64
if b == 64
Use ==.
Ruby
[77, 82, 18
[77, 82, 18]
Close bracket.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
["message", 72]
["message", 72]
Correct.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
items.forEach(function(val) {{ console.log(val); }})
items.forEach((val) => {{ console.log(val); }})
Arrow functions are cleaner.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def foo puts 'test' end
def foo puts 'test' end
Correct.
Ruby
if ($a = 21)
if ($a == 21)
Use ==.
Perl
for (int i=0; i<78; i++) {{}}
for (int i=0; i<78; i++) {{}}
Correct.
Java
if a > 86 puts 'output'
if a > 86 puts 'output' end
Add 'end'.
Ruby
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
let z = 40; z += 1;
let mut z = 40; z += 1;
Need mut to modify.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(38);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(38);
Correct.
Node.js
<user><desc>hello</desc><name>100</name></user
<user><desc>hello</desc><name>100</name></user>
Add closing >.
XML
let result: number | null = null; result.toFixed(96);
let result: number | null = null; if(result!==null) result.toFixed(96);
Null check.
TypeScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
b > 23 & x < 25
b > 23 and x < 25
Use 'and' not '&'.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
compute
compute()
Add parentheses.
Swift
<br></br>
<br>
Self-closing.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
print 'output'
print('output')
print needs parentheses.
Python
if item > 15 print('world')
if item > 15: print('world')
Colon missing after if.
Python
List(15,17,61)
List(15,17,61)
Correct.
Scala
cin >> z;
int z; cin >> z;
Declare variable.
C++
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
var temp int = 'world'
var temp string = 'world'
Type mismatch.
Go
<input type='text' value='message'>
<input type='text' value='message' name='value'>
Add name attribute.
HTML
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
function test(): void {{ return 22; }}
function test(): number {{ return 22; }}
Return type mismatch.
TypeScript
String a = 'data';
String a = "data";
Double quotes.
Java
const z;
const z = 36;
Initialize const.
JavaScript
if (item = 88)
if (item == 88)
Use ==.
R
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if ($data = 78) {{}}
if ($data -eq 78) {{}}
Use -eq.
PowerShell
SELECT name role FROM products;
SELECT name, role FROM products;
Add comma.
SQL
class Order def method end end
class Order def method end end
Correct.
Ruby
'result' + 29
'result' + str(29)
Can't add int to string.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
<hr></hr>
<hr>
Self-closing.
HTML
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
[x*x for x in list if x > 88]
[x*x for x in list if x > 88]
Correct list comprehension.
Python
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
let num = 97; let num = 67;
let num = 97; num = 67;
Duplicate declaration.
JavaScript
<person age=75>
<person age="75">
Quote attribute.
XML
DELETE FROM users WHERE name=79
DELETE FROM users WHERE name=79;
Add semicolon.
SQL
function bar(z) print(z) end
function bar(z) print(z) end
Correct.
Lua
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
var x int
var x int
Correct.
Go
while a > 86 a -= 1
while a > 86: a -= 1
Colon missing after while.
Python